import type { Express, Request, Response } from "express";
import { requireAuth } from "../../pkg/middleware/authMiddleware.js";
import { mainServerSync } from "./controller/servers/matchServers.js";
//admin routes
import users from "./routes/getUserRoles.js";
import grantRoles from "./routes/grantRole.js";
import revokeRoles from "./routes/revokeRole.js";
import servers from "./routes/servers/serverRoutes.js";

export const setupAdminRoutes = (app: Express, basePath: string) => {
	app.use(
		basePath + "/api/admin/server", // will pass bc system admin but this is just telling us we need this
		servers,
	);

	app.use(
		basePath + "/api/admin/users",
		requireAuth("user", ["systemAdmin"]), // will pass bc system admin but this is just telling us we need this
		users,
	);

	app.use(
		basePath + "/api/admin",
		requireAuth("user", ["systemAdmin", "admin"]), // will pass bc system admin but this is just telling us we need this
		grantRoles,
	);

	app.use(
		basePath + "/api/admin",
		requireAuth("user", ["systemAdmin", "admin"]), // will pass bc system admin but this is just telling us we need this
		revokeRoles,
	);

	// run the sync only on startup
	setTimeout(() => {
		mainServerSync();
	}, 5 * 1000);
};
