/**
 * 牛只用途路由
 * 处理cattle_user表相关的API请求
 */

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

/**
 * @swagger
 * /api/cattle-user:
 *   get:
 *     summary: 获取所有牛只用途
 *     tags: [CattleUser]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: integer
 *                       name:
 *                         type: string
 *                       description:
 *                         type: string
 *                       created_at:
 *                         type: string
 *                       updated_at:
 *                         type: string
 *                 message:
 *                   type: string
 *       500:
 *         description: 服务器错误
 */
router.get('/', 
  // requirePermission('cattle:archives:view'), // 临时注释掉认证
  cattleUserController.getAllUsers
)

/**
 * @swagger
 * /api/cattle-user/{id}:
 *   get:
 *     summary: 根据ID获取牛只用途
 *     tags: [CattleUser]
 *     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('cattle:archives:view'),
  cattleUserController.getUserById
)

/**
 * @swagger
 * /api/cattle-user:
 *   post:
 *     summary: 创建牛只用途
 *     tags: [CattleUser]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *             properties:
 *               name:
 *                 type: string
 *                 description: 用途名称
 *               description:
 *                 type: string
 *                 description: 用途描述
 *     responses:
 *       201:
 *         description: 创建成功
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器错误
 */
router.post('/', 
  requirePermission('cattle:archives:create'),
  cattleUserController.createUser
)

/**
 * @swagger
 * /api/cattle-user/{id}:
 *   put:
 *     summary: 更新牛只用途
 *     tags: [CattleUser]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 牛只用途ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *             properties:
 *               name:
 *                 type: string
 *                 description: 用途名称
 *               description:
 *                 type: string
 *                 description: 用途描述
 *     responses:
 *       200:
 *         description: 更新成功
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 牛只用途不存在
 *       500:
 *         description: 服务器错误
 */
router.put('/:id', 
  requirePermission('cattle:archives:update'),
  cattleUserController.updateUser
)

/**
 * @swagger
 * /api/cattle-user/{id}:
 *   delete:
 *     summary: 删除牛只用途
 *     tags: [CattleUser]
 *     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('cattle:archives:delete'),
  cattleUserController.deleteUser
)

module.exports = router
