import { ListDealersUseCase } from "@/contexts/sales/application";
import { NextFunction, Request, Response } from "express";
import { registerDealerRepository } from "../../../../Dealer.repository";
import { ISalesContext } from "../../../../Sales.context";
import { ListDealersController } from "./ListDealers.controller";
import { listDealersPresenter } from "./presenter/ListDealers.presenter";

export const listDealersController = (req: Request, res: Response, next: NextFunction) => {
  const context: ISalesContext = res.locals.context;

  registerDealerRepository(context);
  return new ListDealersController(
    {
      useCase: new ListDealersUseCase(context),
      presenter: listDealersPresenter,
    },
    context
  ).execute(req, res, next);
};
