/**
 * 智能耳标客户端路由
 * 处理iot_jbq_client表相关的API请求
 */

const express = require('express')
const router = express.Router()
const iotJbqClientController = require('../controllers/iotJbqClientController')
const { requirePermission } = require('../middleware/permission')

/**
 * @swagger
 * /api/iot-jbq-client:
 *   get:
 *     summary: 获取所有智能耳标设备
 *     tags: [IotJbqClient]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: cid
 *         schema:
 *           type: string
 *         description: 设备CID
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: pageSize
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页数量
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                 pagination:
 *                   type: object
 *                   properties:
 *                     current:
 *                       type: integer
 *                     pageSize:
 *                       type: integer
 *                     total:
 *                       type: integer
 *                 message:
 *                   type: string
 *       500:
 *         description: 服务器错误
 */
router.get('/', 
  // requirePermission('smart_eartag:view'), // 临时注释掉认证
  iotJbqClientController.getAllClients
)

/**
 * @swagger
 * /api/iot-jbq-client/cid/{cid}:
 *   get:
 *     summary: 根据CID获取智能耳标设备
 *     tags: [IotJbqClient]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: cid
 *         required: true
 *         schema:
 *           type: string
 *         description: 设备CID
 *     responses:
 *       200:
 *         description: 获取成功
 *       404:
 *         description: 设备不存在
 *       500:
 *         description: 服务器错误
 */
router.get('/cid/:cid', 
  // requirePermission('smart_eartag:view'), // 临时注释掉认证
  iotJbqClientController.getClientByCid
)

/**
 * @swagger
 * /api/iot-jbq-client/{id}:
 *   get:
 *     summary: 根据ID获取智能耳标设备
 *     tags: [IotJbqClient]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 设备ID
 *     responses:
 *       200:
 *         description: 获取成功
 *       404:
 *         description: 设备不存在
 *       500:
 *         description: 服务器错误
 */
router.get('/:id', 
  // requirePermission('smart_eartag:view'), // 临时注释掉认证
  iotJbqClientController.getClientById
)

/**
 * @swagger
 * /api/iot-jbq-client/{id}:
 *   put:
 *     summary: 更新智能耳标设备
 *     tags: [IotJbqClient]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 设备ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               bandge_status:
 *                 type: integer
 *                 description: 绑定状态
 *               bound_cattle_id:
 *                 type: integer
 *                 description: 绑定的牛只ID
 *               bound_ear_number:
 *                 type: string
 *                 description: 绑定的耳标号
 *     responses:
 *       200:
 *         description: 更新成功
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 设备不存在
 *       500:
 *         description: 服务器错误
 */
router.put('/:id', 
  // requirePermission('smart_eartag:update'), // 临时注释掉认证
  iotJbqClientController.updateClient
)

/**
 * @swagger
 * /api/iot-jbq-client/{id}:
 *   delete:
 *     summary: 删除智能耳标设备
 *     tags: [IotJbqClient]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 设备ID
 *     responses:
 *       200:
 *         description: 删除成功
 *       404:
 *         description: 设备不存在
 *       500:
 *         description: 服务器错误
 */
router.delete('/:id', 
  // requirePermission('smart_eartag:delete'), // 临时注释掉认证
  iotJbqClientController.deleteClient
)

module.exports = router
