import { InvoiceItem } from "#/server/domain";
import { IInvoicingContext } from "#/server/intrastructure";
import { Collection } from "@rdx/core";

export const invoiceItemPresenter = (items: Collection<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,
      }))
    : [];
