import { IsEmail, IsEnum, IsString, MinLength, ValidateIf } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { HostType } from 'common/enum/HostType.enum';

export class CreateContactDto {
  @IsEnum(HostType)
  @ApiProperty({
    description: 'The client type',
    enum: HostType,
    example: `${HostType.CAN} or ${HostType.DFUK}`,
  })
  client: HostType;

  @IsString()
  @MinLength(2)
  @ApiProperty({
    description: 'First name of the sender (DFUK requires full name here, CAN requires first name)',
    example: 'John',
  })
  firstname: string;

  @ValidateIf(dto => dto.client === HostType.CAN)
  @IsString()
  @ApiProperty({
    description: 'Last name of the sender (Required only for CAN, optional for DFUK)',
    example: 'Doe',
    required: false,
  })
  lastname?: string;

  @IsString()
  @ApiProperty({
    description: 'Phone number of the sender',
    example: '+1234567890',
  })
  phone: string;

  @IsEmail()
  @ApiProperty({
    description: 'The email address of the sender',
    example: 'example@example.com',
  })
  email: string;

  @ValidateIf(dto => dto.client === HostType.DFUK)
  @IsString()
  @MinLength(10)
  @ApiProperty({
    description: 'The subject of the email (Required for DFUK, optional for CAN)',
    example: 'Inquiry about services',
    required: false,
  })
  subject?: string;

  @IsString()
  @MinLength(10)
  @ApiProperty({
    description: 'The message content of the contact email',
    example: 'I would like to know more about your services.',
  })
  body: string;

  // Additional fields for CAN client
  @ValidateIf(dto => dto.client === HostType.CAN)
  @IsString()
  @ApiProperty({
    description: 'Dropdown selection for CAN client (Required for CAN, not needed for DFUK)',
    example: 'General Inquiry',
    required: false,
  })
  dropdownSelection?: string;

  @ValidateIf(dto => dto.client === HostType.CAN)
  @IsString()
  @ApiProperty({
    description: 'Additional parameter based on the selected dropdown for CAN client (Required for CAN, not needed for DFUK)',
    example: 'Specific details about inquiry',
    required: false,
  })
  additionalDetails?: string;
}
