import { MetadataSchema, MoneySchema, PercentageSchema, QuantitySchema } from "@erp/core";
import { z } from "zod/v4";

export const GetVerifactuRecordByIdResponseSchema = z.object({
  id: z.uuid(),
  company_id: z.uuid(),

  invoice_number: z.string(),
  status: z.string(),
  series: z.string(),

  invoice_date: z.string(),
  operation_date: z.string(),

  notes: z.string(),

  language_code: z.string(),
  currency_code: z.string(),

  customer_id: z.string(),
  recipient: z.object({
    id: z.string(),
    name: z.string(),
    tin: z.string(),
    street: z.string(),
    street2: z.string(),
    city: z.string(),
    province: z.string(),
    postal_code: z.string(),
    country: z.string(),
  }),

  taxes: z.string(),

  payment_method: z
    .object({
      payment_id: z.string(),
      payment_description: z.string(),
    })
    .optional(),

  subtotal_amount: MoneySchema,
  discount_percentage: PercentageSchema,
  discount_amount: MoneySchema,
  taxable_amount: MoneySchema,
  taxes_amount: MoneySchema,
  total_amount: MoneySchema,

  items: z.array(
    z.object({
      id: z.uuid(),
      is_non_valued: z.string(),
      position: z.string(),
      description: z.string(),
      quantity: QuantitySchema,
      unit_amount: MoneySchema,

      taxes: z.string(),

      subtotal_amount: MoneySchema,
      discount_percentage: PercentageSchema,
      discount_amount: MoneySchema,
      taxable_amount: MoneySchema,
      taxes_amount: MoneySchema,
      total_amount: MoneySchema,
    })
  ),

  metadata: MetadataSchema.optional(),
});

export type GetVerifactuRecordByIdResponseDTO = z.infer<
  typeof GetVerifactuRecordByIdResponseSchema
>;
