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

export enum Gender {
  MALE = 'male',
  FEMALE = 'female',
  OTHER = 'other',
  PREFER_NOT_TO_SAY = 'prefer not to say',
}

export class DemographicInfoDto {
  @ApiProperty({ enum: Gender, example: Gender.MALE })
  @IsEnum(Gender)
  @IsNotEmpty()
  gender: Gender;

  @ApiProperty({ example: '25' })
  @IsString()
  @IsNotEmpty()
  age: string;

  @ApiProperty({ example: 'California' })
  @IsString()
  @IsNotEmpty()
  state: string;

  @ApiProperty({ example: 'Los Angeles' })
  @IsString()
  @IsNotEmpty()
  district: string;
}

export class UserDetailsDto {
  @ApiProperty({ example: '123456789', required: false })
  @IsString()
  @IsOptional()
  id?: string;
}

export class QuestionResponseDto {
  @ApiProperty({ example: '12345' })
  @IsString()
  @IsNotEmpty()
  questionId: string;

  @ApiProperty({ example: 'What is your favorite color?' })
  @IsString()
  @IsNotEmpty()
  questionText: string;

  @ApiProperty({ example: 'Blue' })
  @IsString()
  @IsNotEmpty()
  answer: string[];
}

export enum QuestionType {
  FINANCIAL_FRAUD = 'financial_fraud',
  HACKED_COMPLAIN = 'hacked_complain',
  OTHER = 'other',
}

export class CreateReportDto {
  @ApiProperty({ type: () => DemographicInfoDto })
  @ValidateNested()
  @Type(() => DemographicInfoDto)
  @IsNotEmpty()
  demographicInfo: DemographicInfoDto;

  @ApiProperty({ type: () => [QuestionResponseDto] })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => QuestionResponseDto)
  @IsNotEmpty()
  responses: QuestionResponseDto[];

  @ApiProperty({ 
    description: 'Type of report being submitted', 
    example: QuestionType.FINANCIAL_FRAUD,
    enum: QuestionType
  })
  @IsString()
  @IsNotEmpty()
  questionType: string; 

  @ApiPropertyOptional({
    type: 'string',
    format: 'binary',
    required: false,
    description: 'Attach a file (1 image, < 1MB)',
  })
  @IsOptional()
  attachment?: any;

  @ApiPropertyOptional({ type: () => UserDetailsDto })
  @IsOptional()
  @ValidateNested()
  @Type(() => UserDetailsDto)
  userDetails?: UserDetailsDto;
}