import { Invoice } from "@/contexts/invoices/domain";
import { Collection } from "@/core";
import { IListInvoicesResponseDTO } from "../../../dto";

export interface IListInvoicesPresenter {
  toDTO: (invoices: Collection<Invoice>) => IListInvoicesResponseDTO[];
}

export const listInvoicesPresenter: IListInvoicesPresenter = {
  toDTO: (invoices: Collection<Invoice>): IListInvoicesResponseDTO[] => {
    return invoices.map((invoice) => {
      const result = {
        id: invoice.id.toPrimitive(),

        invoice_status: invoice.status.toString(),
        invoice_number: invoice.invoiceNumber.toString(),
        invoice_series: invoice.invoiceSeries.toString(),
        issue_date: invoice.issueDate.toISOString(),
        operation_date: invoice.operationDate.toISOString(),
        language_code: "ES",
        currency: invoice.invoiceCurrency.toString(),
        subtotal: invoice.calculateSubtotal().toPrimitive(),
        total: invoice.calculateTotal().toPrimitive(),

        //recipient: InvoiceParticipantPresenter(invoice.recipient),
      };

      return result;
    });
  },
};
