import {
  IsBoolean,
  IsInt,
  IsNumber,
  IsOptional,
  IsString,
  MinLength,
} from "class-validator";
import { Currency } from "@jorgecuadros/database";
import { IsEnum } from "class-validator";

/** Editable policy-header fields. coveragesJson (freeform legacy blob) is not
 *  exposed for editing. Dates arrive as ISO strings and are coerced by the
 *  service. `total` is legacy-dead data — the UI uses netPremium. */
export class CreatePolicyDto {
  @IsString() @MinLength(1) policyNumber!: string;
  @IsString() @MinLength(1) customerId!: string;

  @IsOptional() @IsString() policyTypeId?: string;
  @IsOptional() @IsString() insuranceProviderId?: string;
  @IsOptional() @IsString() agentName?: string;
  @IsOptional() @IsString() policyDate?: string;
  @IsOptional() @IsString() policyFrom?: string;
  @IsOptional() @IsString() policyTo?: string;
  @IsOptional() @IsInt() coveragePeriodDays?: number;
  @IsOptional() @IsNumber() netPremium?: number;
  @IsOptional() @IsNumber() policyFee?: number;
  @IsOptional() @IsNumber() brokerFee?: number;
  @IsOptional() @IsNumber() commission?: number;
  @IsOptional() @IsNumber() total?: number;
  @IsOptional() @IsEnum(Currency) currency?: Currency;
  @IsOptional() @IsString() observations?: string;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsBoolean() endorsement?: boolean;
  @IsOptional() @IsBoolean() liquidated?: boolean;
  @IsOptional() @IsString() liquidationNumber?: string;
  @IsOptional() @IsString() liquidationDate?: string;
}

/** All header fields optional (customerId is not re-assignable on update). */
export class UpdatePolicyDto {
  @IsOptional() @IsString() @MinLength(1) policyNumber?: string;
  @IsOptional() @IsString() policyTypeId?: string;
  @IsOptional() @IsString() insuranceProviderId?: string;
  @IsOptional() @IsString() agentName?: string;
  @IsOptional() @IsString() policyDate?: string;
  @IsOptional() @IsString() policyFrom?: string;
  @IsOptional() @IsString() policyTo?: string;
  @IsOptional() @IsInt() coveragePeriodDays?: number;
  @IsOptional() @IsNumber() netPremium?: number;
  @IsOptional() @IsNumber() policyFee?: number;
  @IsOptional() @IsNumber() brokerFee?: number;
  @IsOptional() @IsNumber() commission?: number;
  @IsOptional() @IsNumber() total?: number;
  @IsOptional() @IsEnum(Currency) currency?: Currency;
  @IsOptional() @IsString() observations?: string;
  @IsOptional() @IsString() notes?: string;
  @IsOptional() @IsBoolean() endorsement?: boolean;
  @IsOptional() @IsBoolean() liquidated?: boolean;
  @IsOptional() @IsString() liquidationNumber?: string;
  @IsOptional() @IsString() liquidationDate?: string;
}
