const express = require("express");
const router = express.Router();
const {
  analyzePermit,
  getPermitsToWork,
  getSinglePermitToWork,
  createPermitToWork,
  updatePermitStatus,
  updatePermitToWork,
} = require("../controllers/permit-to-work");
const authMiddleware = require("../middleware/authMiddleware");

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

// AI Analysis endpoint
router.post("/analyze", analyzePermit);

// CRUD operations
router.get("/", getPermitsToWork);
router.get("/:id", getSinglePermitToWork);
router.post("/", createPermitToWork);
router.put("/:id", updatePermitToWork);
router.patch("/", updatePermitToWork); // Handle PATCH with query params for Form component

// Status update endpoint
router.patch("/:id/status", updatePermitStatus);

module.exports = router;
