import { Router } from "express";
import type { ModuleParams } from "@erp/core/api";
import { build{{pascalCase name}}Dependencies } from "../repositories";
import {
  Create{{pascalCase name}}Controller,
  Delete{{pascalCase name}}Controller,
  Get{{pascalCase name}}Controller,
  List{{pascalCase name}}Controller,
  Update{{pascalCase name}}Controller,
} from "./controllers";

/**
 * Monta las rutas del módulo en `params.app` bajo `params.baseRoutePath/{{kebabCase plural}}`
 * @remarks
 * - Las validaciones DTO están comentadas hasta que existan en `common/dto`.
 */
export const mount{{pascalCase plural}}Routes = (params: ModuleParams) => {
  const router = Router();
  const deps = build{{pascalCase name}}Dependencies(params);

  // TODO: descomentar cuando exista validateRequest y DTOs
  // const validateCreate = validateRequest(Create{{pascalCase name}}Dto);
  // const validateUpdate = validateRequest(Update{{pascalCase name}}Dto);

  router.get("/", (req, res, next) => deps.build.list().bind(req, res, next));
  router.get("/:{{snakeCase name}}_id", (req, res, next) => deps.build.get().bind(req, res, next));
  router.post("/", /* validateCreate, */ (req, res, next) => deps.build.create().bind(req, res, next));
  router.patch("/:{{snakeCase name}}_id", /* validateUpdate, */ (req, res, next) => deps.build.update().bind(req, res, next));
  router.put("/:{{snakeCase name}}_id", /* validateUpdate, */ (req, res, next) => deps.build.update().bind(req, res, next));
  router.delete("/:{{snakeCase name}}_id", (req, res, next) => deps.build.delete().bind(req, res, next));

  params.app.use(`${params.baseRoutePath}/{{kebabCase plural}}`, router);
};
