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

const router = express.Router();

/**
 * @openapi
 * /api/frame_entries:
 *   get:
 *     tags: [FRAME]
 *     summary: List FRAME weekly entries (tenant/campus-scoped)
 *     description: Requires the `READ_FRAME` product-feature permission.
 *     responses:
 *       200:
 *         description: List of FRAME entries.
 *         content:
 *           application/json:
 *             schema: { $ref: '#/components/schemas/ListResponse' }
 *       401: { $ref: '#/components/responses/UnauthorizedError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   post:
 *     tags: [FRAME]
 *     summary: Create a FRAME entry (manager-only; service-gated)
 *     responses:
 *       200: { description: Created. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/frame_entries/{id}:
 *   put:
 *     tags: [FRAME]
 *     summary: Update a FRAME entry (manager-only; service-gated)
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: string, format: uuid }
 *     responses:
 *       200: { description: Updated. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
router.get(
  '/',
  permissions.checkPermissions(FEATURE_PERMISSIONS.READ_FRAME),
  wrapAsync(frame.list),
);
router.post('/', wrapAsync(frame.create));
router.put('/:id', wrapAsync(frame.update));
router.delete('/:id', wrapAsync(frame.destroy));

export default router;
