import { checkUser } from "@/contexts/auth";
import { handleRequest } from "@/contexts/common/infrastructure/express";
import {
  createQuoteController,
  duplicateQuoteController,
  getQuoteController,
  listQuotesController,
  reportQuoteController,
  sendQuoteController,
  setStatusQuoteController,
  updateQuoteController,
} from "@/contexts/sales/infrastructure/express/controllers";
import { getDealerMiddleware } from "@/contexts/sales/infrastructure/express/middlewares/Dealer.middleware";
import { Router } from "express";

export const quoteRouter = (appRouter: Router): void => {
  const quoteRoutes: Router = Router({ mergeParams: true });

  // Users CRUD
  quoteRoutes.get("/", checkUser, getDealerMiddleware, handleRequest(listQuotesController));
  quoteRoutes.get("/:quoteId", checkUser, getDealerMiddleware, handleRequest(getQuoteController));
  quoteRoutes.post("/", checkUser, getDealerMiddleware, handleRequest(createQuoteController));
  quoteRoutes.put(
    "/:quoteId",
    checkUser,
    getDealerMiddleware,
    handleRequest(updateQuoteController)
  );

  // Duplicate
  quoteRoutes.post(
    "/:quoteId/duplicate",
    checkUser,
    getDealerMiddleware,
    handleRequest(duplicateQuoteController)
  );

  // Reports
  quoteRoutes.get(
    "/:quoteId/report",
    checkUser,
    getDealerMiddleware,
    handleRequest(reportQuoteController)
  );

  // Status
  quoteRoutes.put("/:quoteId/setStatus", checkUser, handleRequest(setStatusQuoteController));

  // Send to Uecko
  quoteRoutes.put("/:quoteId/send", checkUser, handleRequest(sendQuoteController));

  /*
  quoteRoutes.post("/", isAdmin, createQuoteController);
  
  quoteRoutes.delete("/:quoteId", isAdmin, getDealerMiddleware, deleteQuoteController);*/

  appRouter.use("/quotes", quoteRoutes);
};
