import { GetInvoiceUseCase } 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 { GetInvoiceController } from "./get-invoice.controller";
import { getInvoicePresenter } from "./presenter";

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

  const useCase = new GetInvoiceUseCase(invoiceService, transactionManager);
  const presenter = getInvoicePresenter;

  return new GetInvoiceController(useCase, presenter);
};
