const express = require("express");
const router = express.Router();
const policyController = require("../controllers/policyController");
const authenticate = require("../middlewares/authenticate");
const authorize = require("../middlewares/authorize");

/**
 * @swagger
 * tags:
 *   name: Policies
 *   description: Policy management APIs
 */

router.post(
  "/create",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Policies']
      #swagger.summary = 'Create a new policy'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.requestBody = {
        required: true,
        content: {
          "application/json": {
            schema: {
              policyId: "POL001",
              name: "Privacy Policy",
              category: "Legal",
              description: "Organization privacy policy",
              effectiveDate: "2023-01-01",
              expiryDate: "2030-12-31",
              status: "Active"
            }
          }
        }
      }
    */
    policyController.createPolicy(req, res);
  }
);

router.get(
  "/",
  authenticate,
  authorize(["admin", "manager", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Policies']
      #swagger.summary = 'Get all policies'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['search'] = { in: 'query', type: 'string' }
      #swagger.parameters['category'] = { in: 'query', type: 'string' }
      #swagger.parameters['status'] = { in: 'query', enum: ['Active','Inactive','Archived'] }
      #swagger.parameters['page'] = { in: 'query', type: 'number' }
      #swagger.parameters['limit'] = { in: 'query', type: 'number' }
    */
    policyController.getPolicies(req, res);
  }
);

router.get(
  "/:id",
  authenticate,
  authorize(["admin", "manager", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Policies']
      #swagger.summary = 'Get policy by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    policyController.getPolicyById(req, res);
  }
);

router.put(
  "/:id",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Policies']
      #swagger.summary = 'Update policy details'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    policyController.updatePolicy(req, res);
  }
);

router.put(
  "/:id/status",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Policies']
      #swagger.summary = 'Update policy status'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.requestBody = {
        required: true,
        content: {
          "application/json": {
            schema: {
              status: "Inactive"
            }
          }
        }
      }
    */
    policyController.updatePolicyStatus(req, res);
  }
);

router.delete(
  "/:id",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Policies']
      #swagger.summary = 'Delete policy (soft delete)'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    policyController.deletePolicy(req, res);
  }
);

module.exports = router;
