import type { Express, Request, Response } from "express";

import healthRoutes from "./routes/healthRoutes.js";
import { setupAuthRoutes } from "../auth/routes/routes.js";

export const setupRoutes = (app: Express, basePath: string) => {
    // Root / health check
    app.use(basePath + "/api/system/health", healthRoutes);

    // all routes
    setupAuthRoutes(app, basePath);

    // always try to go to the app weather we are in dev or in production.
    app.get(basePath + "/", (req: Request, res: Response) => {
        res.redirect(basePath + "/app");
    });

    // Fallback 404 handler
    app.use((req: Request, res: Response) => {
        res.status(404).json({ error: "Not Found" });
    });
};
