import { CreateInvoiceUseCase } from "@/contexts/invoices/application/create-invoice.use-case";
import { InvoiceService } from "@/contexts/invoices/domain";
import { InvoiceRepository, invoiceMapper } from "@/contexts/invoices/intrastructure";
import { SequelizeTransactionManager } from "@/core";
import { Sequelize } from "sequelize";
import { CreateInvoiceController } from "./create-invoice.controller";
import { createInvoicePresenter } from "./presenter";

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

  const useCase = new CreateInvoiceUseCase(invoiceService, transactionManager);
  const presenter = createInvoicePresenter;

  return new CreateInvoiceController(useCase, presenter);
};
