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

/**
 * @swagger
 * tags:
 *   name: Customers
 *   description: Customer management APIs
 */

/* =====================================================
   CREATE CUSTOMER
   POST /customers/create
===================================================== */
router.post(
  "/create",
  authenticate,
  authorize(["admin", "superadmin", "manager", "agent"]),
  (req, res) => {
   /*
  #swagger.tags = ['Customers']
  #swagger.summary = 'Create a new customer'
  #swagger.security = [{ "bearerAuth": [] }]

  #swagger.requestBody = {
    required: true,
    content: {
      "application/json": {
        schema: {
          type: "object",
          required: ["name", "customerNumber"],
          properties: {
            name: {
              type: "string",
              example: "ABC Enterprises"
            },
            customerNumber: {
              type: "string",
              example: "CUST-001"
            },
            email: {
              type: "string",
              example: "contact@abc.com"
            },
            phone: {
              type: "string",
              example: "9876543210"
            },
            address: {
              type: "string",
              example: "Plot 21, Madhapur, Hyderabad"
            },
            state: {
              type: "string",
              example: "Telangana"
            },
            city: {
              type: "string",
              example: "Hyderabad"
            },
            notes: {
              type: "string",
              example: "Preferred corporate customer"
            }
          }
        }
      }
    }
  }
*/

    customerController.createCustomer(req, res);
  }
);

/* =====================================================
   GET ALL CUSTOMERS
   GET /customers
===================================================== */
router.get(
  "/",
  authenticate,
  authorize(["admin", "manager", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Customers']
      #swagger.summary = 'Get all customers'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['search'] = { in: 'query', type: 'string' }
      #swagger.parameters['isActive'] = { in: 'query', type: 'boolean' }
      #swagger.parameters['page'] = { in: 'query', type: 'number' }
      #swagger.parameters['limit'] = { in: 'query', type: 'number' }
    */
    customerController.getAllCustomers(req, res);
  }
);

/* =====================================================
   GET CUSTOMER BY ID
   GET /customers/:id
===================================================== */
router.get(
  "/:id",
  authenticate,
  authorize(["admin", "manager", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Customers']
      #swagger.summary = 'Get customer by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    customerController.getCustomerById(req, res);
  }
);

/* =====================================================
   UPDATE CUSTOMER
   PUT /customers/:id
===================================================== */
router.put(
  "/:id",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Customers']
      #swagger.summary = 'Update customer details'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    customerController.updateCustomer(req, res);
  }
);

/* =====================================================
   DELETE CUSTOMER (SOFT DELETE)
   DELETE /customers/:id
===================================================== */
router.delete(
  "/:id",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Customers']
      #swagger.summary = 'Delete customer (soft delete)'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    customerController.deleteCustomer(req, res);
  }
);

module.exports = router;
