import { z } from "zod/v4";

export const CustomerFormSchema = z.object({
  reference: z.string().optional(),

  is_company: z.string().default("true"),
  name: z
    .string({
      error: "El nombre es obligatorio",
    })
    .min(1, "El nombre no puede estar vacío"),
  trade_name: z.string().optional(),
  tin: z.string().optional(),
  default_taxes: z.array(z.string()).default([]),

  street: z.string().optional(),
  street2: z.string().optional(),
  city: z.string().optional(),
  province: z.string().optional(),
  postal_code: z.string().optional(),
  country: z
    .string({
      error: "El país es obligatorio",
    })
    .min(1, "El país no puede estar vacío")
    .toLowerCase() // asegura minúsculas
    .default("es"),

  email_primary: z.string().optional(),
  email_secondary: z.string().optional(),
  phone_primary: z.string().optional(),
  phone_secondary: z.string().optional(),
  mobile_primary: z.string().optional(),
  mobile_secondary: z.string().optional(),

  fax: z.string().optional(),
  website: z.string().optional(),

  legal_record: z.string().optional(),

  language_code: z
    .string({
      error: "El idioma es obligatorio",
    })
    .min(1, "Debe indicar un idioma")
    .toUpperCase() // asegura mayúsculas
    .default("es"),

  currency_code: z
    .string({
      error: "La moneda es obligatoria",
    })
    .min(1, "La moneda no puede estar vacía")
    .toUpperCase() // asegura mayúsculas
    .default("EUR"),
});

export type CustomerFormData = z.infer<typeof CustomerFormSchema>;

export const defaultCustomerFormData: CustomerFormData = {
  reference: "",

  is_company: "true",
  name: "",
  trade_name: "",
  tin: "",
  default_taxes: ["iva_21"],

  street: "",
  street2: "",
  city: "",
  province: "",
  postal_code: "",
  country: "es",

  email_primary: "",
  email_secondary: "",
  phone_primary: "",
  phone_secondary: "",
  mobile_primary: "",
  mobile_secondary: "",

  fax: "",
  website: "",

  legal_record: "",
  language_code: "es",
  currency_code: "EUR",
};
