import { Type } from 'class-transformer';
import {
  IsArray,
  IsIn,
  IsInt,
  IsOptional,
  IsString,
  MaxLength,
  Min,
  ValidateNested,
} from 'class-validator';
import { QUESTION_TYPES, QuestionOptionDto } from './create-question.dto';

export class UpdateQuestionDto {
  @IsOptional()
  @IsString()
  questionText?: string;

  @IsOptional()
  @IsIn(QUESTION_TYPES as unknown as string[])
  questionType?: string;

  @IsOptional()
  @IsString()
  @MaxLength(1024)
  imagePath?: string;

  @IsOptional()
  @IsString()
  explanation?: string;

  @IsOptional()
  @IsInt()
  @Min(1)
  score?: number;

  @IsOptional()
  @IsInt()
  @Min(0)
  orderIndex?: number;

  /** When present, replaces the full option set for this question. */
  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => QuestionOptionDto)
  options?: QuestionOptionDto[];
}
