import {
  IsEmail,
  IsEnum,
  IsOptional,
  IsString,
  MaxLength,
  IsNotEmpty,
  Length,
  Matches,
} from "class-validator";

// Enums
export enum CustomerStatusDto {
  Active = "Active",
  Pending = "Pending",
  Inactive = "Inactive",
}

export enum CustomerTypeDto {
  Importer = "Importer",
  Exporter = "Exporter",
  Supplier = "Supplier",
}

// DTO
export class CreateCustomerDto {
  // Basic identity
  @IsString()
  @IsNotEmpty()
  userId!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  firstName!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  lastName!: string;

  @IsEmail()
  @IsNotEmpty()
  email!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(20)
  phone!: string;

  // Company info
  @IsString()
  @IsNotEmpty()
  @MaxLength(200)
  companyName!: string;

  @IsEmail()
  @IsNotEmpty()
  companyEmail!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(20)
  companyPhone!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  companyLocation!: string;

  @IsString()
  @IsNotEmpty()
  companyAddress!: string;

  // Classification
  @IsOptional()
  @IsEnum(CustomerTypeDto)
  customerType?: CustomerTypeDto;

  @IsOptional()
  @IsEnum(CustomerStatusDto)
  status?: CustomerStatusDto;

  // Legal identifiers
  @IsString()
  @IsNotEmpty()
  @Length(10, 10)
  @Matches(/^\d+$/, { message: "TIN must contain only digits" })
  tinNumber!: string;

  @IsString()
  @IsNotEmpty()
  @Length(16, 16)
  @Matches(/^\d+$/, { message: "FAN must contain only digits" })
  fanNumber!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(50)
  vatNumber!: string;

  // Contact person
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  contactPersonName!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(20)
  contactPersonPhone!: string;

  // Management
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  generalManagerName!: string;

  @IsEmail()
  @IsNotEmpty()
  generalManagerEmail!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(20)
  generalManagerPhone!: string;

  // POA (Power of Attorney)
  @IsOptional()
  @IsString()
  @MaxLength(100)
  poaName?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  poaPhone?: string;

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

  @IsOptional()
  @IsEmail()
  poaEmail?: string;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  poaLocation?: string;

  // Extra
  @IsOptional()
  @IsString()
  notes?: string;
}