import { Hono } from "hono";
import type { AppConfig } from "../config.js";
import { MiddlewareManager } from "../middlewares/middleware.js";
import type { BaseEnv } from "../types/app.types.js";
import { getAdminActionsRouter } from "./adminActions.js";
import { getAdminAuthRouter } from "./adminAuth.js";
import { getAdminDatasetsRouter } from "./adminDatasets.js";
import { getAdminOverviewRouter } from "./adminOverview.js";
import { getAdminTablesRouter } from "./adminTables.js";

export const getAdminRouter = (config: AppConfig) => {
  const adminRouter = new Hono<BaseEnv>();
  const middlewareManager = MiddlewareManager.getInstance();

  adminRouter.route("/auth", getAdminAuthRouter(config));

  adminRouter.use("/overview", middlewareManager.adminAuth);
  adminRouter.use("/overview/*", middlewareManager.adminAuth);
  adminRouter.use("/tables", middlewareManager.adminAuth);
  adminRouter.use("/tables/*", middlewareManager.adminAuth);
  adminRouter.use("/datasets", middlewareManager.adminAuth);
  adminRouter.use("/datasets/*", middlewareManager.adminAuth);
  adminRouter.use("/actions", middlewareManager.adminAuth);
  adminRouter.use("/actions/*", middlewareManager.adminAuth);

  adminRouter.route("/overview", getAdminOverviewRouter());
  adminRouter.route("/tables", getAdminTablesRouter());
  adminRouter.route("/datasets", getAdminDatasetsRouter());
  adminRouter.route("/actions", getAdminActionsRouter());

  return adminRouter;
};
