import { z } from "zod/v4";

import { PaginationSchema } from "@erp/core";
import { ArrayElement } from "@repo/rdx-utils";
import {
  CreateCustomerInvoiceRequestSchema,
  GetCustomerInvoiceByIdResponseSchema,
  ListCustomerInvoicesResponseSchema,
  UpdateCustomerInvoiceByIdRequestSchema,
} from "../../common";

export const CustomerInvoiceSchema = GetCustomerInvoiceByIdResponseSchema.omit({
  metadata: true,
});
export const CustomerInvoiceCreateSchema = CreateCustomerInvoiceRequestSchema;
export const CustomerInvoiceUpdateSchema = UpdateCustomerInvoiceByIdRequestSchema;

// Tipos (derivados de Zod o DTOs del backend)
export type CustomerInvoice = z.infer<typeof CustomerInvoiceSchema>;
export type CustomerInvoiceRecipient = CustomerInvoice["recipient"];
export type CustomerInvoiceItem = ArrayElement<CustomerInvoice["items"]>;

export type CustomerInvoiceCreateInput = z.infer<typeof CustomerInvoiceCreateSchema>; // Cuerpo para crear
export type CustomerInvoiceUpdateInput = z.infer<typeof CustomerInvoiceUpdateSchema>; // Cuerpo para actualizar

// Resultado de consulta con criteria (paginado, etc.)
export const CustomerInvoicesPageSchema = ListCustomerInvoicesResponseSchema.omit({
  metadata: true,
});

export type PaginatedResponse = z.infer<typeof PaginationSchema>;
export type CustomerInvoicesPage = z.infer<typeof CustomerInvoicesPageSchema>;

// Ítem simplificado dentro del listado (no toda la entidad)
export type CustomerInvoiceSummary = Omit<ArrayElement<CustomerInvoicesPage["items"]>, "metadata">;
