/**
 * @openapi
 * /api/permissions:
 *   get:
 *     tags: [Permissions]
 *     summary: List permissions (tenant-scoped)
 *     description: Requires READ_PERMISSIONS.
 *     responses:
 *       200:
 *         description: List payload.
 *         content:
 *           application/json:
 *             schema: { $ref: '#/components/schemas/ListResponse' }
 *       401: { $ref: '#/components/responses/UnauthorizedError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   post:
 *     tags: [Permissions]
 *     summary: Create a permissions record
 *     description: Requires CREATE_PERMISSIONS.
 *     responses:
 *       200: { description: Created. }
 *       400: { $ref: '#/components/responses/ValidationError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/permissions/count:
 *   get:
 *     tags: [Permissions]
 *     summary: Count permissions
 *     description: Requires READ_PERMISSIONS.
 *     responses:
 *       200: { description: Count. }
 * /api/permissions/autocomplete:
 *   get:
 *     tags: [Permissions]
 *     summary: Autocomplete permissions
 *     description: Requires READ_PERMISSIONS.
 *     responses:
 *       200: { description: Autocomplete results. }
 * /api/permissions/bulk-import:
 *   post:
 *     tags: [Permissions]
 *     summary: Bulk-import permissions from CSV
 *     description: Requires CREATE_PERMISSIONS.
 *     responses:
 *       200: { description: Imported. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/permissions/deleteByIds:
 *   post:
 *     tags: [Permissions]
 *     summary: Delete multiple permissions records
 *     description: Requires DELETE_PERMISSIONS.
 *     responses:
 *       200: { description: Deleted. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/permissions/{id}:
 *   get:
 *     tags: [Permissions]
 *     summary: Get a permissions record by id
 *     description: Requires READ_PERMISSIONS.
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: string, format: uuid }
 *     responses:
 *       200: { description: The record. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *       404: { description: Not found. }
 *   put:
 *     tags: [Permissions]
 *     summary: Update a permissions record
 *     description: Requires UPDATE_PERMISSIONS.
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: string, format: uuid }
 *     responses:
 *       200: { description: Updated. }
 *       400: { $ref: '#/components/responses/ValidationError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   delete:
 *     tags: [Permissions]
 *     summary: Delete a permissions record
 *     description: Requires DELETE_PERMISSIONS.
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: string, format: uuid }
 *     responses:
 *       200: { description: Deleted. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
import express from 'express';
import { wrapAsync } from '@/api/http/request';
import * as permissionsController from '@/api/controllers/permissions.controller';
import permissions from '@/middlewares/check-permissions';

const router = express.Router();

router.use(permissions.checkCrudPermissions('permissions'));

router.post('/', wrapAsync(permissionsController.create));
router.post('/bulk-import', wrapAsync(permissionsController.bulkImport));
router.put('/:id', wrapAsync(permissionsController.update));
router.delete('/:id', wrapAsync(permissionsController.remove));
router.post('/deleteByIds', wrapAsync(permissionsController.deleteByIds));
router.get('/', wrapAsync(permissionsController.list));
router.get('/count', wrapAsync(permissionsController.count));
router.get('/autocomplete', wrapAsync(permissionsController.autocomplete));
router.get('/:id', wrapAsync(permissionsController.findById));

export default router;
