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

export class QuizAnswerDto {
  @IsInt()
  questionId!: number;

  /** Option ids the learner selected; a single-answer question sends one. */
  @IsArray()
  @IsInt({ each: true })
  optionIds!: number[];
}

export class SubmitQuizDto {
  @IsInt()
  activityId!: number;

  @IsOptional()
  @IsString()
  @IsNotEmpty()
  @MaxLength(128)
  anonymousSessionId?: string;

  @IsArray()
  @ArrayMinSize(1)
  @ValidateNested({ each: true })
  @Type(() => QuizAnswerDto)
  answers!: QuizAnswerDto[];
}
