import { Invoice } from "@/contexts/invoicing/domain";
import { IInvoicingContext } from "@/contexts/invoicing/intrastructure/InvoicingContext";
import { IUpdateInvoice_Response_DTO } from "@shared/contexts";
import { invoiceItemPresenter } from "./InvoiceItem.presenter";
import { InvoiceParticipantPresenter } from "./InvoiceParticipant.presenter";

export interface IUpdateInvoicePresenter {
  map: (invoice: Invoice, context: IInvoicingContext) => IUpdateInvoice_Response_DTO;
}

export const updateInvoicePresenter: IUpdateInvoicePresenter = {
  map: (invoice: Invoice, context: IInvoicingContext): IUpdateInvoice_Response_DTO => {
    return {
      id: invoice.id.toString(),

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

      //sender: {}, //await InvoiceParticipantPresenter(invoice.senderId, context),

      recipient: InvoiceParticipantPresenter(invoice.recipient, context),

      items: invoiceItemPresenter(invoice.items, context),
    };
  },
};
