import { Request, Router } from "express";
import ClientRoute from "./client.js";
import UserRoute from "./user.js";
import RegCodeRoute from "./regcode.js";
import PermissionRoute from "./permission.js";
import { GetUserMiddleware } from "../middlewares/user.js";
import RequestError, { HttpStatusCode } from "../../helper/request_error.js";

const AdminRoute: Router = Router();

AdminRoute.use(GetUserMiddleware(true, true), (req: Request, res, next) => {
   if (!req.isAdmin)
      throw new RequestError(
         "You have no permission to access this API",
         HttpStatusCode.FORBIDDEN
      );
   else next();
});

AdminRoute.use("/client", ClientRoute);
AdminRoute.use("/regcode", RegCodeRoute);
AdminRoute.use("/user", UserRoute);
AdminRoute.use("/permission", PermissionRoute);
export default AdminRoute;
