import { IsEnum, IsOptional, IsString, IsEmail, IsDateString, ValidateIf, IsNotEmpty } from 'class-validator'
import { ClientType } from '../../common/schemas'

export class CreateClientFolderDto {
  @IsEnum(['individual', 'corporate'])
  clientType: ClientType

  // Individual
  @ValidateIf(o => o.clientType === 'individual')
  @IsString() @IsNotEmpty()
  firstName?: string

  @ValidateIf(o => o.clientType === 'individual')
  @IsString() @IsNotEmpty()
  lastName?: string

  @IsOptional() @IsString() nationality?: string
  @IsOptional() @IsString() passportNumber?: string
  @IsOptional() @IsString() idType?: string
  @IsOptional() @IsString() visaNumber?: string
  @IsOptional() @IsString() visaType?: string
  @IsOptional() @IsDateString() visaExpiry?: string
  @IsOptional() @IsDateString() dateOfBirth?: string

  // Corporate
  @ValidateIf(o => o.clientType === 'corporate')
  @IsString() @IsNotEmpty()
  companyName?: string

  @IsOptional() @IsString() registrationNumber?: string
  @IsOptional() @IsString() boiStatus?: string

  // Shared (legacy primary)
  @IsOptional() @IsEmail() email?: string
  @IsOptional() @IsString() phone?: string
  @IsOptional() @IsString() lineId?: string
  @IsOptional() @IsString() address?: string
  @IsOptional() addresses?: { line1: string; line2?: string; city?: string; state?: string; postal?: string; country: string; type: string }[]
  @IsOptional() folderTeam?: { name: string; role: string; firm?: string; email?: string; phone?: string; notes?: string }[]
  @IsOptional() folderParties?: { name: string; type: string; organization?: string; role?: string; email?: string; phone?: string; barNumber?: string; notes?: string }[]
  @IsOptional() folderAgencies?: any[]
  @IsOptional() complianceEvents?: any[]

  // Structured multi-contact
  @IsOptional() phones?: { countryCode: string; dialCode: string; number: string; type: string }[]
  @IsOptional() emails?: { address: string; type: string }[]
  @IsOptional() @IsString() region?: string

  @IsString() @IsNotEmpty()
  originatingAttorney: string

  @IsString() @IsNotEmpty()
  responsibleAttorney: string

  @IsOptional() @IsString() notes?: string

  @IsOptional()
  retainerThreshold?: number

  @IsOptional() @IsString() currency?: string

  @IsOptional()
  billingConfig?: Record<string, unknown>
}
