/**
 * @openapi
 * /api/class_attendance/summary:
 *   get:
 *     tags: [ClassAttendance]
 *     summary: Roll-up attendance totals for the caller's tier (per date)
 *     description: Requires READ_ATTENDANCE. Sums class attendance across the caller's subtree (org/school/campus/class).
 *     responses:
 *       200: { description: Roll-up rows. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/class_attendance/{classId}/{date}:
 *   put:
 *     tags: [ClassAttendance]
 *     summary: Record a class's daily attendance aggregate (teacher)
 *     description: Requires FILL_ATTENDANCE. Rolls up to campus/school/org.
 *     parameters:
 *       - in: path
 *         name: classId
 *         required: true
 *         schema: { type: string, format: uuid }
 *       - in: path
 *         name: date
 *         required: true
 *         schema: { type: string, format: date }
 *     responses:
 *       200: { description: Saved. }
 *       400: { $ref: '#/components/responses/ValidationError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
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 classAttendance from '@/api/controllers/class_attendance.controller';

const router = express.Router();

router.get(
  '/summary',
  permissions.checkPermissions(FEATURE_PERMISSIONS.READ_ATTENDANCE),
  wrapAsync(classAttendance.summary),
);
router.put(
  '/:classId/:date',
  permissions.checkPermissions(FEATURE_PERMISSIONS.FILL_ATTENDANCE),
  wrapAsync(classAttendance.upsert),
);

export default router;
