import { ApiProperty } from "@nestjs/swagger";
import { CustomerDocType } from "@prisma/client";
import { IsEmail, IsEnum, IsObject, IsOptional, IsString, Length, Matches } from "class-validator";

export class CreateCustomerDto {
  @ApiProperty({ required: false, example: "cliente@acme.com.py", format: "email" })
  @IsOptional()
  @IsEmail()
  email?: string;

  @ApiProperty({ required: false, example: "Juan Pérez" })
  @IsOptional()
  @IsString()
  @Length(1, 200)
  name?: string;

  @ApiProperty({
    required: false,
    enum: CustomerDocType,
    example: CustomerDocType.ruc,
    description: "Tipo de documento. Usar `other` si ninguno aplica.",
  })
  @IsOptional()
  @IsEnum(CustomerDocType)
  docType?: CustomerDocType;

  @ApiProperty({ required: false, example: "80012345-6" })
  @IsOptional()
  @IsString()
  @Length(1, 60)
  docNumber?: string;

  @ApiProperty({ required: false, example: "+595981000111" })
  @IsOptional()
  @IsString()
  @Length(1, 30)
  phone?: string;

  @ApiProperty({ required: false, example: "PY", description: "ISO 3166-1 alpha-2." })
  @IsOptional()
  @Matches(/^[A-Z]{2}$/, { message: "country must be uppercase ISO 3166-1 alpha-2" })
  country?: string;

  @ApiProperty({
    required: false,
    description: "Metadata libre (key/value) para correlación con sistemas del merchant.",
    example: { erpCustomerId: "C-00123" },
  })
  @IsOptional()
  @IsObject()
  metadata?: Record<string, unknown>;
}
