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

const authenticate = require("../../middlewares/authenticate");
const formControllers = require("../../controllers/mobile/formConfigController");

/**
 * ---------------------------------------
 * GET FORM CONFIG BY KEY
 * ---------------------------------------
 */
router.get("/:key", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Forms']
    #swagger.summary = 'Get dynamic form configuration by key'
    #swagger.description = 'Fetch server-driven form configuration so frontend can render form dynamically'

    #swagger.security = [{
      "bearerAuth": []
    }]

    #swagger.parameters['key'] = {
      in: 'path',
      description: 'Form key (e.g. CREATE_CUSTOMER_FORM)',
      required: true,
      type: 'string'
    }

    #swagger.responses[200] = {
      description: 'Form configuration fetched successfully',
      schema: {
        success: true,
        data: {
          key: "CREATE_CUSTOMER_FORM",
          title: "Create Customer",
          fields: [
            {
              name: "name",
              label: "Customer Name",
              type: "text",
              required: true
            }
          ]
        }
      }
    }

    #swagger.responses[404] = {
      description: 'Form not found or inactive'
    }

    #swagger.responses[401] = {
      description: 'Unauthorized'
    }

    #swagger.responses[500] = {
      description: 'Server error'
    }
  */
  formControllers.getFormByAgent(req, res);
});

module.exports = router;
