/**
 * 牛只类型路由
 * 处理cattle_type表相关的API请求
 */

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

/**
 * @swagger
 * /api/cattle-type:
 *   get:
 *     summary: 获取所有牛只类型
 *     tags: [CattleType]
 *     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'), // 临时注释掉认证
  cattleTypeController.getAllTypes
)

/**
 * @swagger
 * /api/cattle-type/{id}:
 *   get:
 *     summary: 根据ID获取牛只类型
 *     tags: [CattleType]
 *     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'),
  cattleTypeController.getTypeById
)

/**
 * @swagger
 * /api/cattle-type:
 *   post:
 *     summary: 创建牛只类型
 *     tags: [CattleType]
 *     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'),
  cattleTypeController.createType
)

/**
 * @swagger
 * /api/cattle-type/{id}:
 *   put:
 *     summary: 更新牛只类型
 *     tags: [CattleType]
 *     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'),
  cattleTypeController.updateType
)

/**
 * @swagger
 * /api/cattle-type/{id}:
 *   delete:
 *     summary: 删除牛只类型
 *     tags: [CattleType]
 *     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'),
  cattleTypeController.deleteType
)

module.exports = router
