import { Type } from 'class-transformer';
import {
  IsArray,
  IsBoolean,
  IsIn,
  IsInt,
  IsNotEmpty,
  IsOptional,
  IsString,
  MaxLength,
  Min,
  ValidateNested,
} from 'class-validator';

export const QUESTION_TYPES = [
  'MCQ_SINGLE',
  'MCQ_MULTIPLE',
  'TRUE_FALSE',
  'IMAGE_BASED',
  'MATCHING',
] as const;

export class QuestionOptionDto {
  @IsString()
  @IsNotEmpty()
  optionText!: string;

  @IsOptional()
  @IsBoolean()
  isCorrect?: boolean;

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

export class CreateQuestionDto {
  @IsOptional()
  @IsInt()
  activityId?: number;

  @IsString()
  @IsNotEmpty()
  questionText!: string;

  @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;

  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => QuestionOptionDto)
  options?: QuestionOptionDto[];
}
