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 safety_quiz_results from '@/api/controllers/safety_quiz_results.controller';

const router = express.Router();

/**
 * @openapi
 * /api/safety_quiz_results:
 *   get:
 *     tags: [Quizzes]
 *     summary: List safety (QBS) quiz results
 *     description: >
 *       Authenticated; the service returns own results, or the compliance report
 *       for report-eligible roles.
 *     responses:
 *       200:
 *         description: Results.
 *         content:
 *           application/json:
 *             schema: { $ref: '#/components/schemas/ListResponse' }
 *       401: { $ref: '#/components/responses/UnauthorizedError' }
 *   post:
 *     tags: [Quizzes]
 *     summary: Submit a safety quiz result
 *     description: Requires the `TAKE_QUIZ` action permission.
 *     responses:
 *       200: { description: Submitted. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
router.get('/', wrapAsync(safety_quiz_results.list));
router.post(
  '/',
  permissions.checkPermissions(FEATURE_PERMISSIONS.TAKE_QUIZ),
  wrapAsync(safety_quiz_results.create),
);

export default router;
