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

export class CloneQuestionsDto {
  @ApiProperty({ description: 'Template form section ID to clone questions into', example: 1 })
  @IsInt()
  @IsNotEmpty()
  templateFormSectionId: number;

  @ApiProperty({ description: 'Master form section ID to clone questions from', example: 1 })
  @IsInt()
  @IsNotEmpty()
  masterFormSectionId: number;

  @ApiProperty({ 
    description: 'Specific master question IDs to clone (if not cloning all)', 
    required: false,
    type: [Number]
  })
  @IsOptional()
  @IsArray()
  @IsInt({ each: true })
  specificQuestionIds?: number[];

  @ApiProperty({ 
    description: 'Whether to override existing cloned questions (delete and re-clone)', 
    default: false,
    required: false 
  })
  @IsOptional()
  @IsBoolean()
  override?: boolean = false;

  // Field Overrides - Customize question fields during cloning
  @ApiProperty({ 
    description: 'Override the question text during cloning', 
    required: false,
    example: 'What is your full name?'
  })
  @IsOptional()
  @IsString()
  questionTextOverride?: string;

  @ApiProperty({ 
    description: 'Override the question type during cloning', 
    required: false,
    enum: QuestionType
  })
  @IsOptional()
  @IsEnum(QuestionType)
  questionTypeOverride?: QuestionType;

  @ApiProperty({ 
    description: 'Override the answer type during cloning', 
    required: false,
    enum: AnswerType
  })
  @IsOptional()
  @IsEnum(AnswerType)
  answerTypeOverride?: AnswerType;

  @ApiProperty({ 
    description: 'Override the answer location during cloning', 
    required: false
  })
  @IsOptional()
  @IsString()
  @MaxLength(1024)
  answerLocationOverride?: string;

  @ApiProperty({ 
    description: 'Override the option configuration during cloning', 
    required: false,
    type: [Object]
  })
  @IsOptional()
  @IsObject({ each: true })
  optionConfigOverride?: Record<string, any>[];

  @ApiProperty({ 
    description: 'Override the question configuration during cloning', 
    required: false,
    type: Object
  })
  @IsOptional()
  @IsObject()
  configOverride?: Record<string, any>;

  @ApiProperty({
    description: 'Override the conditional configuration during cloning', 
    required: false,
    type: Object,
  })
  @IsOptional()
  @IsObject()
  conditionalConfigOverride?: Record<string, any>;

  @ApiProperty({
    description: 'Override the display order during cloning', 
    required: false,
    example: 5
  })
  @IsOptional()
  @IsInt()
  displayOrderOverride?: number;

  @ApiProperty({ description: 'User ID performing the clone operation', required: false })
  @IsOptional()
  @IsInt()
  createdBy?: number;
}
