import { Invoice, InvoiceItem } from "../../../../domain";
import { IGetInvoiceResponseDTO } from "../../../dto";

export interface IGetInvoicePresenter {
  toDTO: (invoice: Invoice) => IGetInvoiceResponseDTO;
}

export const getInvoicePresenter: IGetInvoicePresenter = {
  toDTO: (invoice: Invoice): IGetInvoiceResponseDTO => ({
    id: invoice.id.toPrimitive(),

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

    items:
      invoice.items.size() > 0
        ? invoice.items.map((item: InvoiceItem) => ({
            description: item.description.toString(),
            quantity: item.quantity.toPrimitive(),
            unit_measure: "",
            unit_price: item.unitPrice.toPrimitive(),
            subtotal: item.calculateSubtotal().toPrimitive(),
            //tax_amount: item.calculateTaxAmount().toPrimitive(),
            total: item.calculateTotal().toPrimitive(),
          }))
        : [],

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

    /*recipient: await InvoiceParticipantPresenter(invoice.recipient, context),
      items: invoiceItemPresenter(invoice.items, context),

      payment_term: {
        payment_type: "",
        due_date: "",
      },

      due_amount: {
        currency: invoice.currency.toString(),
        precision: 2,
        amount: 0,
      },

      custom_fields: [],

      metadata: {
        create_time: "",
        last_updated_time: "",
        delete_time: "",
      },*/
  }),
};
