import { ModuleParams } from "@/core";
import { Application, NextFunction, Request, Response, Router } from "express";
import { Sequelize } from "sequelize";
import { buildGetInvoiceController, buildListInvoicesController } from "../../presentation";

export const invoicesRouter = (params: ModuleParams) => {
  const { app, database, baseRoutePath } = params as {
    app: Application;
    database: Sequelize;
    baseRoutePath: string;
  };

  const routes: Router = Router({ mergeParams: true });

  routes.get(
    "/",
    //checkTabContext,
    //checkUser,
    (req: Request, res: Response, next: NextFunction) => {
      buildListInvoicesController(database).execute(req, res, next);
    }
  );

  routes.get(
    "/:invoiceId",
    //checkTabContext,
    //checkUser,
    (req: Request, res: Response, next: NextFunction) => {
      buildGetInvoiceController(database).execute(req, res, next);
    }
  );

  /*routes.post(
    "/",
    validateAndParseBody(ICreateInvoiceRequestSchema, { sanitize: false }),
    //checkTabContext,
    //checkUser,
    (req: Request, res: Response, next: NextFunction) => {
      buildCreateInvoiceController(database).execute(req, res, next);
    }
  );

  routes.put(
    "/:invoiceId",
    validateAndParseBody(IUpdateInvoiceRequestSchema),
    checkTabContext,
    //checkUser,
    (req: Request, res: Response, next: NextFunction) => {
      buildUpdateInvoiceController().execute(req, res, next);
    }
  );

  routes.delete(
    "/:invoiceId",
    validateAndParseBody(IDeleteInvoiceRequestSchema),
    checkTabContext,
    //checkUser,
    (req: Request, res: Response, next: NextFunction) => {
      buildDeleteInvoiceController().execute(req, res, next);
    }
  );*/

  app.use(`${baseRoutePath}/invoices`, routes);
};
