import express from "express";
import { createSessionExchangeHandler, JWT_AUD } from "../../../shared/hse-jwt/index.js";
import masterRoutes from "./masterRoutes.js";
import locationRoutes from "./locationRoutes.js";
import userRoutes from "./userRoutes.js";
import ticketRoutes from "./ticketRoutes.js";
import formRoutes from "./formRoutes.js";
import permitRoutes from "./permitRoutes.js";
import { requireAuth } from "../middlewares/authMiddleware.js";

const router = express.Router();

router.get("/health", (req, res) => {
  res.json({ status: "ok" });
});

router.post("/ptw/auth/session", createSessionExchangeHandler(JWT_AUD.PTW));

/**
 * PTW APIs under `/api/ptw` — any authenticated HSE user (session JWT, aud: ptw).
 */
const ptwRouter = express.Router();

ptwRouter.use(requireAuth, masterRoutes);
ptwRouter.use(requireAuth, locationRoutes);
ptwRouter.use(requireAuth, userRoutes);
ptwRouter.use(requireAuth, ticketRoutes);
ptwRouter.use(requireAuth, formRoutes);
ptwRouter.use(requireAuth, permitRoutes);

router.use("/ptw", ptwRouter);

export default router;
