import { OpenAPIHono } from "@hono/zod-openapi";
import { areModulesIn } from "./utils/moduleCheck.js";

// routes
import getModules from "./route/modules/getModules.js";
import updateModule from "./route/modules/updateModules.js";
import addModule from "./route/modules/addModule.js";
import addSetting from "./route/settings/addSetting.js";
import getSettings from "./route/settings/getSettings.js";
import updateSetting from "./route/settings/updateSetting.js";
import { areSettingsIn } from "./utils/settingsCheck.js";
import { serversCheckPoint } from "./utils/serverData.js";
import getServers from "./route/servers/getServers.js";
import updateServer from "./route/updates/updateServer.js";
import { setPerms } from "./utils/testServerPerms.js";
import serviceControl from "./route/servers/serverContorl.js";
import { areSubModulesIn } from "./utils/subModuleCheck.js";
import getSubmodules from "./route/modules/getSubModules.js";
import updateSubModule from "./route/modules/updateSubModules.js";

// making sure all modules are in properly
setTimeout(async () => {
    await areSettingsIn();
    await areModulesIn();
    await serversCheckPoint();
    await setPerms();
    await areSubModulesIn();
}, 5000);

const app = new OpenAPIHono();

const routes = [
    getModules,
    updateModule,
    addModule,
    getSubmodules,
    updateSubModule,
    // settings
    addSetting,
    getSettings,
    updateSetting,
    // serverData
    getServers,
    updateServer,
    serviceControl,
] as const;

// app.route("/server", modules);
const appRoutes = routes.forEach((route) => {
    app.route("/server", route);
});

app.all("/server/*", (c) => {
    return c.json({
        success: false,
        message:
            "You encountered a route that dose not exist on the server routes",
    });
});
export default app;
