import { InvoiceItem } from "@/contexts/invoicing/domain/InvoiceItems";
import { IInvoicingContext } from "@/contexts/invoicing/intrastructure/InvoicingContext";
import { ICollection, IMoney_Response_DTO } from "@shared/contexts";

export const invoiceItemPresenter = (
  items: ICollection<InvoiceItem>,
  context: IInvoicingContext
) =>
  items.totalCount > 0
    ? items.items.map((item: InvoiceItem) => ({
        description: item.description.toString(),
        quantity: item.quantity.toString(),
        unit_measure: "",
        unit_price: item.unitPrice.toPrimitive() as IMoney_Response_DTO,
        subtotal: item.calculateSubtotal().toPrimitive() as IMoney_Response_DTO,
        tax_amount: item.calculateTaxAmount().toPrimitive() as IMoney_Response_DTO,
        total: item.calculateTotal().toPrimitive() as IMoney_Response_DTO,
      }))
    : [];
