const express = require("express");
const router = express.Router();
const {
  getStudies,
  getSingleStudy,
  createStudy,
  deleteStudy,
  getDashboard,
  generateNodesController,
  analyzeNodeController,
  generateHazardsController,
  chatController,
  closeAction,
} = require("../controllers/hazop");
const authMiddleware = require("../middleware/authMiddleware");

// All routes require authentication
router.use(authMiddleware);

// Static paths before parameterized routes
router.get("/dashboard", getDashboard);

// Study Management endpoints
router.get("/studies", getStudies);
router.get("/studies/:id", getSingleStudy);
router.post("/studies", createStudy);
router.delete("/studies/:id", deleteStudy);

// AI Services endpoints
router.post("/ai/generate-nodes", generateNodesController);
router.post("/ai/analyze-node", analyzeNodeController);
router.post("/ai/generate-hazards", generateHazardsController);
router.post("/ai/chat", chatController);

// Action Management endpoints
router.patch("/actions/:id/close", closeAction);

module.exports = router;
