/**
 * @openapi
 * /api/users:
 *   get:
 *     tags: [Users]
 *     summary: List users (tenant-scoped)
 *     description: Requires READ_USERS.
 *     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: [Users]
 *     summary: Create a users record
 *     description: Requires CREATE_USERS.
 *     responses:
 *       200: { description: Created. }
 *       400: { $ref: '#/components/responses/ValidationError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/users/count:
 *   get:
 *     tags: [Users]
 *     summary: Count users
 *     description: Requires READ_USERS.
 *     responses:
 *       200: { description: Count. }
 * /api/users/autocomplete:
 *   get:
 *     tags: [Users]
 *     summary: Autocomplete users
 *     description: Requires READ_USERS.
 *     responses:
 *       200: { description: Autocomplete results. }
 * /api/users/bulk-import:
 *   post:
 *     tags: [Users]
 *     summary: Bulk-import users from CSV
 *     description: Requires CREATE_USERS.
 *     responses:
 *       200: { description: Imported. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/users/deleteByIds:
 *   post:
 *     tags: [Users]
 *     summary: Delete multiple users records
 *     description: Requires DELETE_USERS.
 *     responses:
 *       200: { description: Deleted. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/users/{id}:
 *   get:
 *     tags: [Users]
 *     summary: Get a users record by id
 *     description: Requires READ_USERS.
 *     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: [Users]
 *     summary: Update a users record
 *     description: Requires UPDATE_USERS.
 *     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: [Users]
 *     summary: Delete a users record
 *     description: Requires DELETE_USERS.
 *     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 users from '@/api/controllers/users.controller';
import permissions from '@/middlewares/check-permissions';

const router = express.Router();

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

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

export default router;
