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

const router = express.Router();

// Acknowledging policies is restricted to the campus staff roles via the
// ACK_POLICY product-feature permission; the service scopes reads to the
// caller's own acknowledgments.
router.use(permissions.checkPermissions(FEATURE_PERMISSIONS.ACK_POLICY));

/**
 * @openapi
 * /api/policy_acknowledgments:
 *   get:
 *     tags: [Policy Documents]
 *     summary: List the current user's policy acknowledgments
 *     description: Requires the ACK_POLICY permission (the four campus staff roles).
 *     responses:
 *       200:
 *         description: The caller's acknowledgments.
 *         content:
 *           application/json:
 *             schema: { $ref: '#/components/schemas/ListResponse' }
 *       401: { $ref: '#/components/responses/UnauthorizedError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   post:
 *     tags: [Policy Documents]
 *     summary: Acknowledge a policy document's current version
 *     description: >
 *       Records the caller's acknowledgment of the document's current version
 *       (idempotent per user × document × version). Requires ACK_POLICY.
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               data:
 *                 type: object
 *                 required: [policyDocumentId]
 *                 properties:
 *                   policyDocumentId: { type: string, format: uuid }
 *     responses:
 *       200: { description: Acknowledged. }
 *       400: { $ref: '#/components/responses/ValidationError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
router.get('/', wrapAsync(policy_acknowledgments.list));
router.post('/', wrapAsync(policy_acknowledgments.acknowledge));

export default router;
