import { ApiProperty } from '@nestjs/swagger';
import { IsInt, IsNotEmpty, IsObject, IsOptional, IsString, IsEnum, MaxLength } from 'class-validator';
import { QuestionType } from 'src/common/enum/question-type.enum';
import { AnswerType } from 'src/common/enum/answer-type.enum';

export class CreateTemplateQuestionDto {
  @ApiProperty({ description: 'Template form section ID', example: 1 })
  @IsInt()
  @IsNotEmpty()
  templateFormSectionId: number;

  @ApiProperty({ description: 'Master question ID (if cloned from master)', required: false, type: Number })
  @IsOptional()
  @IsInt()
  masterQuestionId?: number;

  @ApiProperty({ description: 'Unique question code', example: 'Q_FIRSTNAME' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  questionCode: string;

  @ApiProperty({ description: 'Question binding key for data mapping', example: 'firstName' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  bindingKey: string;

  @ApiProperty({ description: 'Question text displayed to user', example: 'What is your first name?' })
  @IsString()
  @IsNotEmpty()
  questionText: string;

  @ApiProperty({ description: 'Type of question', enum: QuestionType })
  @IsEnum(QuestionType)
  @IsNotEmpty()
  questionType: QuestionType;

  @ApiProperty({ description: 'Type of answer expected', enum: AnswerType })
  @IsEnum(AnswerType)
  @IsNotEmpty()
  answerType: AnswerType;

  @ApiProperty({ description: 'Location where answer is stored', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(1024)
  answerLocation?: string;

  @ApiProperty({ description: 'Configuration for question options (dropdown, radio, etc.)', required: false, type: [Object] })
  @IsOptional()
  @IsObject({ each: true })
  optionConfig?: Record<string, any>[];

  @ApiProperty({ description: 'Additional question configuration (validation, visibility, etc.)', type: Object })
  @IsObject()
  @IsNotEmpty()
  config: Record<string, any>;

  @ApiProperty({
    description: 'Conditional configuration for question visibility/prefill logic', 
    required: false,
    type: Object,
  })
  @IsOptional()
  @IsObject()
  conditionalConfig?: Record<string, any>;

  @ApiProperty({ description: 'Display order within the section', example: 1, required: false })
  @IsOptional()
  @IsInt()
  displayOrder?: number;

  @ApiProperty({ description: 'User ID who created this question', required: false })
  @IsOptional()
  @IsInt()
  createdBy?: number;
}
