const express = require("express");
const router = express.Router();

const employeeBenefitsController = require("../../controllers/hrandpayrollsController/employeeBenefitsController");
const authenticate = require("../../middlewares/authenticate");

/**
 * @swagger
 * tags:
 *   name: Employee Benefits
 *   description: Employee benefits creation, listing, update and deletion APIs
 */

/* ===========================
   ✅ CREATE EMPLOYEE BENEFITS
=========================== */

router.post(
  "/create",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Employee Benefits']
      #swagger.summary = 'Create employee benefits record'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['employee_id'] = {
        in: 'body',
        type: 'string',
        description: 'Employee ID',
        required: true
      }
      #swagger.parameters['org_id'] = {
        in: 'body',
        type: 'string',
        description: 'Organization ID',
        required: true
      }
      #swagger.parameters['health_insurance_applicable'] = {
        in: 'body',
        type: 'string',
        description: 'Health insurance applicable (Yes/No)',
        required: false
      }
      #swagger.parameters['insurance_provider_name'] = {
        in: 'body',
        type: 'string',
        description: 'Insurance provider name',
        required: false
      }
      #swagger.parameters['policy_number'] = {
        in: 'body',
        type: 'string',
        description: 'Policy number',
        required: false
      }
      #swagger.parameters['coverage_type'] = {
        in: 'body',
        type: 'string',
        description: 'Coverage type',
        required: false
      }
      #swagger.parameters['coverage_amount'] = {
        in: 'body',
        type: 'number',
        description: 'Coverage amount',
        required: false
      }
      #swagger.parameters['premium_amount'] = {
        in: 'body',
        type: 'number',
        description: 'Premium amount',
        required: false
      }
      #swagger.parameters['employer_contribution'] = {
        in: 'body',
        type: 'string',
        description: 'Employer contribution',
        required: false
      }
      #swagger.parameters['employee_contribution'] = {
        in: 'body',
        type: 'string',
        description: 'Employee contribution',
        required: false
      }
      #swagger.parameters['insurance_start_date'] = {
        in: 'body',
        type: 'string',
        format: 'date',
        description: 'Insurance start date',
        required: false
      }
      #swagger.parameters['insurance_end_date'] = {
        in: 'body',
        type: 'string',
        format: 'date',
        description: 'Insurance end date',
        required: false
      }
      #swagger.parameters['dependent_coverage_details'] = {
        in: 'body',
        type: 'string',
        description: 'Dependent coverage details',
        required: false
      }
      #swagger.parameters['provident_fund_applicable'] = {
        in: 'body',
        type: 'string',
        description: 'Provident fund applicable (Yes/No)',
        required: false
      }
      #swagger.parameters['pension_scheme_applicable'] = {
        in: 'body',
        type: 'string',
        description: 'Pension scheme applicable (Yes/No)',
        required: false
      }
      #swagger.parameters['employee_contribution_percent'] = {
        in: 'body',
        type: 'number',
        description: 'Employee contribution percentage',
        required: false
      }
      #swagger.parameters['employer_contribution_percent'] = {
        in: 'body',
        type: 'number',
        description: 'Employer contribution percentage',
        required: false
      }
      #swagger.parameters['gratuity_eligible'] = {
        in: 'body',
        type: 'string',
        description: 'Gratuity eligible (Yes/No)',
        required: false
      }
      #swagger.parameters['gratuity_start_date'] = {
        in: 'body',
        type: 'string',
        format: 'date',
        description: 'Gratuity start date',
        required: false
      }
      #swagger.parameters['leave_policy_assigned'] = {
        in: 'body',
        type: 'string',
        description: 'Leave policy assigned',
        required: false
      }
      #swagger.parameters['annual_leave_balance'] = {
        in: 'body',
        type: 'number',
        description: 'Annual leave balance',
        required: false
      }
      #swagger.parameters['sick_leave_balance'] = {
        in: 'body',
        type: 'number',
        description: 'Sick leave balance',
        required: false
      }
      #swagger.parameters['casual_leave_balance'] = {
        in: 'body',
        type: 'number',
        description: 'Casual leave balance',
        required: false
      }
      #swagger.parameters['maternity_paternity_leave_eligible'] = {
        in: 'body',
        type: 'string',
        description: 'Maternity/Paternity leave eligible (Yes/No)',
        required: false
      }
      #swagger.parameters['comp_off_eligibility'] = {
        in: 'body',
        type: 'string',
        description: 'Comp-off eligibility (Yes/No)',
        required: false
      }
      #swagger.parameters['leave_encashment_applicable'] = {
        in: 'body',
        type: 'string',
        description: 'Leave encashment applicable (Yes/No)',
        required: false
      }
      #swagger.parameters['housing_allowance_hra'] = {
        in: 'body',
        type: 'number',
        description: 'Housing allowance (HRA)',
        required: false
      }
      #swagger.parameters['transport_allowance'] = {
        in: 'body',
        type: 'number',
        description: 'Transport allowance',
        required: false
      }
      #swagger.parameters['meal_allowance'] = {
        in: 'body',
        type: 'number',
        description: 'Meal allowance',
        required: false
      }
      #swagger.parameters['travel_allowance'] = {
        in: 'body',
        type: 'number',
        description: 'Travel allowance',
        required: false
      }
      #swagger.parameters['mobile_internet_reimbursement'] = {
        in: 'body',
        type: 'number',
        description: 'Mobile/Internet reimbursement',
        required: false
      }
      #swagger.parameters['special_allowance'] = {
        in: 'body',
        type: 'number',
        description: 'Special allowance',
        required: false
      }
      #swagger.parameters['bonus_eligibility'] = {
        in: 'body',
        type: 'string',
        description: 'Bonus eligibility (Yes/No)',
        required: false
      }
      #swagger.parameters['bonus_percentage_amount'] = {
        in: 'body',
        type: 'string',
        description: 'Bonus percentage or amount',
        required: false
      }
      #swagger.parameters['benefits_effective_date'] = {
        in: 'body',
        type: 'string',
        format: 'date',
        description: 'Benefits effective date',
        required: false
      }
      #swagger.parameters['benefits_expiry_date'] = {
        in: 'body',
        type: 'string',
        format: 'date',
        description: 'Benefits expiry date',
        required: false
      }
      #swagger.parameters['remarks_notes'] = {
        in: 'body',
        type: 'string',
        description: 'Remarks or notes',
        required: false
      }
    */
    employeeBenefitsController.createEmployeeBenefits(req, res);
  }
);

/* ===========================
   ✅ UPDATE EMPLOYEE BENEFITS
=========================== */

router.put(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Employee Benefits']
      #swagger.summary = 'Update employee benefits by ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = {
        in: 'path',
        type: 'integer',
        description: 'Benefits record ID',
        required: true
      }
    */
    employeeBenefitsController.updateBenefits(req, res);
  }
);

/* ===========================
   ✅ GET ALL EMPLOYEE BENEFITS
=========================== */

router.get(
  "/all",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Employee Benefits']
      #swagger.summary = 'Get all employee benefits records with pagination and filters'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['page'] = {
        in: 'query',
        type: 'integer',
        description: 'Page number',
        default: 1,
        required: false
      }
      #swagger.parameters['limit'] = {
        in: 'query',
        type: 'integer',
        description: 'Records per page',
        default: 10,
        required: false
      }
      #swagger.parameters['org_id'] = {
        in: 'query',
        type: 'string',
        description: 'Filter by organization ID',
        required: false
      }
      #swagger.parameters['search'] = {
        in: 'query',
        type: 'string',
        description: 'Search by employee name or code',
        required: false
      }
    */
    employeeBenefitsController.getAllBenefits(req, res);
  }
);

/* ===========================
   ✅ GET BENEFITS SUMMARY
=========================== */

router.get(
  "/summary",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Employee Benefits']
      #swagger.summary = 'Get benefits summary statistics'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['org_id'] = {
        in: 'query',
        type: 'string',
        description: 'Organization ID',
        required: false
      }
    */
    employeeBenefitsController.getBenefitsSummary(req, res);
  }
);

/* ===========================
   ✅ GET BENEFITS BY EMPLOYEE
=========================== */

router.get(
  "/employee/:employee_id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Employee Benefits']
      #swagger.summary = 'Get benefits records by employee ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['employee_id'] = {
        in: 'path',
        type: 'string',
        description: 'Employee ID',
        required: true
      }
    */
    employeeBenefitsController.getBenefitsByEmployee(req, res);
  }
);


router.get(
  "/pending-employees",
  authenticate,
  (req, res) => {
     /*
      #swagger.tags = ['Employee Onboarding']
      #swagger.summary = 'Get employee onboarding list'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    employeeBenefitsController.getEmployeesForBenefits(req, res);
    }
);
/* ===========================
   ✅ GET BENEFITS BY ID
=========================== */

router.get(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Employee Benefits']
      #swagger.summary = 'Get benefits record by ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = {
        in: 'path',
        type: 'integer',
        description: 'Benefits record ID',
        required: true
      }
    */
    employeeBenefitsController.getBenefitsById(req, res);
  }
);

/* ===========================
   ✅ DELETE EMPLOYEE BENEFITS
=========================== */

router.delete(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Employee Benefits']
      #swagger.summary = 'Soft delete benefits record by ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = {
        in: 'path',
        type: 'integer',
        description: 'Benefits record ID',
        required: true
      }
    */
    employeeBenefitsController.deleteBenefits(req, res);
  }
);

module.exports = router;