import { Router } from 'express';

import { authenticate } from '../../middlewares/auth.middleware';

import { sessionsController } from './sessions.controller';

/**
 * EN: Create and configure session routes
 * VI: Tạo và cấu hình routes cho session
 */
export const createSessionRouter = (): Router => {
    const router = Router();

    /**
     * @swagger
     * /api/{version}/sessions:
     *   get:
     *     summary: Get active sessions
     *     description: List all active sessions for the current user
     *     tags: [Sessions]
     *     security:
     *       - bearerAuth: []
     *     parameters:
     *       - in: path
     *         name: version
     *         required: true
     *         schema:
     *           type: string
     *           default: v1
     *         description: API version
     *     responses:
     *       200:
     *         description: Sessions retrieved successfully
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       type: array
     *                       items:
     *                         $ref: '#/components/schemas/Session'
     *       401:
     *         description: Unauthorized
     */
    router.get('/', authenticate(), sessionsController.getUserSessions.bind(sessionsController));

    /**
     * @swagger
     * /api/{version}/sessions:
     *   delete:
     *     summary: Revoke all sessions
     *     description: Revoke all active sessions for the current user except the current one
     *     tags: [Sessions]
     *     security:
     *       - bearerAuth: []
     *     parameters:
     *       - in: path
     *         name: version
     *         required: true
     *         schema:
     *           type: string
     *           default: v1
     *         description: API version
     *     responses:
     *       200:
     *         description: All sessions revoked successfully
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       401:
     *         description: Unauthorized
     */
    router.delete('/', authenticate(), sessionsController.revokeAllSessions.bind(sessionsController));

    /**
     * @swagger
     * /api/{version}/sessions/{sessionId}:
     *   delete:
     *     summary: Revoke session
     *     description: Revoke a specific session
     *     tags: [Sessions]
     *     security:
     *       - bearerAuth: []
     *     parameters:
     *       - in: path
     *         name: version
     *         required: true
     *         schema:
     *           type: string
     *           default: v1
     *         description: API version
     *       - in: path
     *         name: sessionId
     *         required: true
     *         schema:
     *           type: string
     *         description: Session ID to revoke
     *     responses:
     *       200:
     *         description: Session revoked successfully
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       401:
     *         description: Unauthorized
     *       404:
     *         description: Session not found
     */
    router.delete('/:sessionId', authenticate(), sessionsController.revokeSession.bind(sessionsController));

    return router;
};
