import express from 'express';
import { wrapAsync } from '@/api/http/request';
import permissions from '@/middlewares/check-permissions';
import { FEATURE_PERMISSIONS } from '@/shared/constants/product-permissions';
import * as personality_quiz_results from '@/api/controllers/personality_quiz_results.controller';

const router = express.Router();

/**
 * @openapi
 * /api/personality_quiz_results/me:
 *   get:
 *     tags: [Quizzes]
 *     summary: Get the current user's personality result
 *     responses:
 *       200: { description: The user's result. }
 *       401: { $ref: '#/components/responses/UnauthorizedError' }
 *   put:
 *     tags: [Quizzes]
 *     summary: Save the current user's personality result
 *     description: Requires the `TAKE_QUIZ` action permission.
 *     responses:
 *       200: { description: Saved. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/personality_quiz_results/distribution:
 *   get:
 *     tags: [Quizzes]
 *     summary: Personality distribution report (report-eligible roles)
 *     responses:
 *       200: { description: Distribution. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
router.get('/me', wrapAsync(personality_quiz_results.getCurrentUserResult));
router.put(
  '/me',
  permissions.checkPermissions(FEATURE_PERMISSIONS.TAKE_QUIZ),
  wrapAsync(personality_quiz_results.upsertCurrentUserResult),
);
router.get('/distribution', wrapAsync(personality_quiz_results.distribution));

export default router;
