import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsArray, IsBoolean, IsDate, IsInt, IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator';

export class CreateSurveyDto {
  @ApiProperty({ description: 'Survey title' })
  @IsString()
  @IsNotEmpty()
  title: string;

  @ApiProperty({ description: 'Survey description' })
  @IsString()
  @IsNotEmpty()
  description: string;

  @ApiProperty({ description: 'Target audience' })
  @IsString()
  @IsNotEmpty()
  targetAudience: string;

  @ApiProperty({ description: 'Closing date' })
  @IsOptional()
  @IsDate()
  closingDate?: Date;

  @ApiProperty({ description: 'Publication status' })
  @IsBoolean()
  published: boolean;

  @ApiProperty({ description: 'Survey questions' })
  @IsArray()
  @ValidateNested({ each: true }) // Asegura que cada elemento sea validado individualmente
  @Type(() => QuestionDto) // Evita que se envuelva en otro array
  questions: any[];
}



class QuestionDto {
  @IsString()
  id: string;

  @IsInt()
  position: number;

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

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

  @IsBoolean()
  required: boolean;

  @IsString()
  type: string;

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

class OptionsDto {
  @IsString()
  id: string; 

  @IsString()
  text: string; 
}