import { ApiProperty } from "@nestjs/swagger"
import { Transform, Type } from "class-transformer"
import {
  IsOptional,
  IsString,
  IsInt,
  IsDateString,
  IsArray,
  ValidateNested,
  IsEnum,
} from "class-validator"
import { CustomerPhoneNumberDto } from "./customer-phone-numbers.dto"

export enum CustomerType {
  PATIENT = "Patient",
  VIP_PATIENT = "VIP Patient",
  VIP = "VIP",
  STAFF = "Staff",
  VISITOR = "Visitor",
}

export class CreateCustomerDto {
  @ApiProperty({
    example: "John Doe",
    description: "Full name of the customer",
    required: false,
  })
  @IsOptional()
  @IsString()
  customer_name?: string

  @ApiProperty({
    example: "Patient",
    description: "Type of the customer",
    enum: CustomerType,
    required: false,
    nullable: true,
  })
  @IsOptional()
  @IsEnum(CustomerType, {
    message: "customer_type must be a valid enum value",
  })
  @Transform(({ value }) =>
    value === null || value === "" ? undefined : value,
  )
  customer_type?: CustomerType

  @ApiProperty({
    example: "1980-05-10",
    description: "Date of birth (YYYY-MM-DD)",
    required: false,
  })
  @IsOptional()
  date_of_birth?: string

  @ApiProperty({
    example: "male",
    description: "Gender of the customer",
    required: false,
  })
  @IsOptional()
  @IsString()
  gender?: string

  @ApiProperty({
    example: "123 Main St",
    description: "Primary address",
    required: false,
  })
  @IsOptional()
  @IsString()
  primary_address?: string

  @ApiProperty({
    example: "Apt 456",
    description: "Secondary address",
    required: false,
  })
  @IsOptional()
  @IsString()
  secondary_address?: string

  @ApiProperty({
    example: "560001",
    description: "Zip code",
    required: false,
  })
  @IsOptional()
  @IsString()
  zip_code?: string

  @ApiProperty({
    example: "1980-05-10",
    description: "Visa start date (YYYY-MM-DD)",
    required: false,
  })
  @IsOptional()
  visa_start_date?: string

  @ApiProperty({
    example: "1980-05-10",
    description: "Visa end date (YYYY-MM-DD)",
    required: false,
  })
  @IsOptional()
  visa_end_date?: string

  @ApiProperty({
    example: "+91",
    description: "Country code (e.g. +91)",
  })
  @IsOptional()
  @IsString()
  country_code: string

  @ApiProperty({
    example: "9876543210",
    description: "Phone number",
    required: false,
  })
  @IsOptional()
  @IsString()
  phone_number?: string

  @ApiProperty({
    example: "john@example.com",
    description: "Email address",
    required: false,
  })
  @IsOptional()
  @IsString()
  email?: string

  @ApiProperty({
    example: "REF123456",
    description: "Reference number",
    required: false,
  })
  @IsOptional()
  @IsString()
  reference_number?: string

  @ApiProperty({
    example: "PRN78910",
    description: "PRN number",
    required: false,
  })
  @IsOptional()
  @IsString()
  prn_number?: string

  @ApiProperty({
    example: "Initial consultation episode",
    description: "Episode description or reference",
    required: false,
  })
  @IsOptional()
  @IsString()
  episode?: string

  @ApiProperty({
    example: "2025-07-08",
    description: "Date of log entry (YYYY-MM-DD)",
    required: false,
  })
  @IsOptional()
  @IsDateString()
  log_date?: string

  @ApiProperty({
    example: "log_letter_123.pdf",
    description: "Uploaded file path or name for letter of guarantee",
    required: false,
  })
  @IsOptional()
  @IsString()
  letter_of_guarantee?: string

  @ApiProperty({
    example: true,
    description: "Whether the customer is a medical tourist",
    required: false,
  })
  @IsOptional()
  is_medical_tourist?: string

  @ApiProperty({
    example: "Cardiology",
    description: "Department assigned to the customer",
    required: false,
  })
  @IsOptional()
  @IsString()
  department?: string

  @ApiProperty({
    example: "Senior Consultant",
    description: "Job title of the customer",
    required: false,
  })
  @IsOptional()
  @IsString()
  job_title?: string

  @ApiProperty({
    example: "active",
    description: "Status of the customer",
    required: false,
  })
  @IsOptional()
  @IsString()
  status?: string

  @ApiProperty({
    example: 1,
    description: "Form wizard progress step",
    required: false,
  })
  @IsOptional()
  @IsInt()
  current_step?: number

  @ApiProperty({ example: 1, description: "dispatcher ", required: false })
  @IsOptional()
  @IsInt()
  dispatcher_id?: number

  @ApiProperty({ example: 1, description: "Client ID", required: false })
  @IsOptional()
  @IsInt()
  client_company_id?: number

  @ApiProperty({
    example: 2,
    description: "Client Contact ID",
    required: false,
  })
  @IsOptional()
  @IsInt()
  client_contact_id?: number

  @ApiProperty({ example: 3, description: "City ID", required: false })
  @IsOptional()
  @IsInt()
  city_id?: number

  @ApiProperty({ example: 4, description: "State ID", required: false })
  @IsOptional()
  @IsInt()
  state_id?: number

  @ApiProperty({ example: 91, description: "Country ID", required: false })
  @IsOptional()
  @IsInt()
  country_id?: number

  @ApiProperty({ example: 5, description: "Hospital ID", required: false })
  @IsOptional()
  @IsInt()
  hospital_id?: number

  @ApiProperty({ example: 6, description: "Vehicle Type ID", required: false })
  @IsOptional()
  @IsInt()
  vehicle_type_id?: number

  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CustomerPhoneNumberDto)
  phone_numbers?: CustomerPhoneNumberDto[]
}
