import { validateAndParseBody } from "@repo/shared";
import { Express } from "express";
import {
  buildCreateInvoiceController,
  buildGetInvoiceController,
  buildListInvoicesController,
  ICreateInvoiceRequestSchema,
} from "../../presentation";

import { NextFunction, Request, Response, Router } from "express";

export const invoicesRouter = (app: Express) => {
  const routes: Router = Router({ mergeParams: true });

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

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

  routes.post(
    "/",
    validateAndParseBody(ICreateInvoiceRequestSchema, { sanitize: false }),
    //checkTabContext,
    //checkUser,
    (req: Request, res: Response, next: NextFunction) => {
      buildCreateInvoiceController().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("/invoices", routes);
};
