import { z } from "zod/v4";

const ClientTypeSchema = z.enum(["company", "person", "pa", "condo"]);

const VatTypeSchema = z.object({
	description: z.string().nullish(),
	e_invoice: z.boolean().nullish(),
	editable: z.boolean().nullish(),
	ei_description: z.string().nullish(),
	ei_type: z.string().nullish(),
	id: z.number().nullish(),
	is_disabled: z.boolean().nullish(),
	notes: z.string().nullish(),
	value: z.number().nullish(),
});

const PaymentTermsTypeSchema = z.enum(["standard", "end_of_month"]);
const PaymentMethodTypeSchema = z.enum(["standard", "riba"]);
const PaymentAccountTypeSchema = z.enum(["standard", "bank"]);
const PaymentAccountSchema = z.object({
	cuc: z.string().nullish(),
	iban: z.string().nullish(),
	id: z.number().nullish(),
	name: z.string().nullish(),
	sia: z.string().nullish(),
	type: PaymentAccountTypeSchema.optional(),
	virtual: z.boolean().nullish(),
});

const PaymentMethodDetailsSchema = z.object({
	description: z.string().nullish(),
	title: z.string().nullish(),
});

const PaymentMethodSchema = z.object({
	bank_beneficiary: z.string().nullish(),
	bank_iban: z.string().nullish(),
	bank_name: z.string().nullish(),
	default_payment_account: PaymentAccountSchema.nullish(),
	details: z.array(PaymentMethodDetailsSchema).optional(),
	ei_payment_method: z.string().nullish(),
	id: z.number().nullish(),
	is_default: z.boolean().nullish(),
	name: z.string().nullish(),
	type: PaymentMethodTypeSchema.optional(),
});

export const ClientSchema = z.object({
	address_city: z.string().nullish(),
	address_extra: z.string().nullish(),
	address_postal_code: z.string().nullish(),
	address_province: z.string().nullish(),
	address_street: z.string().nullish(),
	bank_iban: z.string().nullish(),
	bank_name: z.string().nullish(),
	bank_swift_code: z.string().nullish(),
	certified_email: z.string().nullish(),
	code: z.string().nullish(),
	contact_person: z.string().nullish(),
	country: z.string().nullish(),
	country_iso: z.string().nullish(),
	created_at: z.string().nullish(),
	default_discount: z.number().nullish(),
	default_payment_method: PaymentMethodSchema.optional(),
	default_payment_terms: z.number().nullish(),
	default_payment_terms_type: PaymentTermsTypeSchema.optional(),
	default_vat: VatTypeSchema.nullish(),
	discount_highlight: z.boolean().nullish(),
	e_invoice: z.boolean().nullish(),
	ei_code: z.string().nullish(),
	email: z.string().nullish(),
	fax: z.string().nullish(),
	first_name: z.string().nullish(),
	has_intent_declaration: z.boolean().nullish(),
	id: z.number().nullish(),
	intent_declaration_protocol_date: z.string().nullish(),
	intent_declaration_protocol_number: z.string().nullish(),
	last_name: z.string().nullish(),
	name: z.string().nullish(),
	notes: z.string().nullish(),
	phone: z.string().nullish(),
	shipping_address: z.string().nullish(),
	tax_code: z.string().nullish(),
	type: ClientTypeSchema.nullish(),
	updated_at: z.string().nullish(),
	vat_number: z.string().nullish(),
});
