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

export class UpdateMasterQuestionDto {
  @ApiProperty({ description: 'Binding key for data mapping', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  bindingKey?: string;

  @ApiProperty({ description: 'Master form section ID', required: false })
  @IsOptional()
  @IsInt()
  masterFormSectionId?: number;

  @ApiProperty({ description: 'Question text', required: false })
  @IsOptional()
  @IsString()
  questionText?: string;

  @ApiProperty({
    description: 'Question type (UI control)',
    enum: QuestionType,
    required: false,
  })
  @IsOptional()
  @IsEnum(QuestionType)
  questionType?: QuestionType;

  @ApiProperty({
    description: 'Answer type (data type)',
    enum: AnswerType,
    required: false,
  })
  @IsOptional()
  @IsEnum(AnswerType)
  answerType?: AnswerType;

  @ApiProperty({ description: 'Answer storage location', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(1024)
  answerLocation?: string;

  @ApiProperty({
    description: 'Option configuration for choice-type questions',
    required: false,
    type: 'array',
    items: { type: 'object' },
  })
  @IsOptional()
  @IsObject({ each: true })
  optionConfig?: Record<string, any>[];

  @ApiProperty({
    description: 'Question configuration',
    type: Object,
    required: false,
  })
  @IsOptional()
  @IsObject()
  config?: Record<string, any>;

  @ApiProperty({ description: 'Whether question is active', required: false })
  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

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