import { getDatabase } from "@/config";

import {
  buildGetInvoiceController,
  buildListInvoicesController,
} from "@/contexts/invoices/presentation";
import { NextFunction, Request, Response, Router } from "express";

export const invoicesRouter = (appRouter: Router) => {
  const routes: Router = Router({ mergeParams: true });
  const database = getDatabase();

  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);
    }
  );*/

  appRouter.use("/invoices", routes);
};
