import { ListInvoicesUseCase } from "@/contexts/invoices/application";
import { InvoiceService } from "@/contexts/invoices/domain";
import { InvoiceRepository, invoiceMapper } from "@/contexts/invoices/intrastructure";
import { SequelizeTransactionManager } from "@/core";
import { Sequelize } from "sequelize";
import { ListInvoicesController } from "./list-invoices.controller";
import { listInvoicesPresenter } from "./presenter";

export const buildListInvoicesController = (database: Sequelize) => {
  const transactionManager = new SequelizeTransactionManager(database);
  const invoiceRepository = new InvoiceRepository(database, invoiceMapper);
  const invoiceService = new InvoiceService(invoiceRepository);

  const useCase = new ListInvoicesUseCase(invoiceService, transactionManager);
  const presenter = listInvoicesPresenter;

  return new ListInvoicesController(useCase, presenter);
};
