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

const router = express.Router();

/**
 * @openapi
 * /api/campus_attendance/configs:
 *   get:
 *     tags: [Campus Attendance]
 *     summary: List campus attendance configs
 *     description: Requires `READ_ATTENDANCE`.
 *     responses:
 *       200: { description: Configs. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/campus_attendance/configs/{campusKey}:
 *   put:
 *     tags: [Campus Attendance]
 *     summary: Upsert a campus attendance config
 *     description: Requires the `FILL_ATTENDANCE` action permission.
 *     parameters:
 *       - in: path
 *         name: campusKey
 *         required: true
 *         schema: { type: string }
 *     responses:
 *       200: { description: Upserted. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/campus_attendance/summaries:
 *   get:
 *     tags: [Campus Attendance]
 *     summary: List campus daily attendance summaries
 *     description: Requires `READ_ATTENDANCE`.
 *     responses:
 *       200: { description: Summaries. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/campus_attendance/summaries/{campusKey}/{date}:
 *   put:
 *     tags: [Campus Attendance]
 *     summary: Upsert a campus daily attendance summary
 *     description: Requires the `FILL_ATTENDANCE` action permission.
 *     parameters:
 *       - in: path
 *         name: campusKey
 *         required: true
 *         schema: { type: string }
 *       - in: path
 *         name: date
 *         required: true
 *         schema: { type: string, format: date }
 *     responses:
 *       200: { description: Upserted. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
router.get(
  '/configs',
  permissions.checkPermissions(FEATURE_PERMISSIONS.READ_ATTENDANCE),
  wrapAsync(campusAttendance.listConfigs),
);
router.put(
  '/configs/:campusKey',
  permissions.checkPermissions(FEATURE_PERMISSIONS.FILL_ATTENDANCE),
  wrapAsync(campusAttendance.upsertConfig),
);
router.get(
  '/summaries',
  permissions.checkPermissions(FEATURE_PERMISSIONS.READ_ATTENDANCE),
  wrapAsync(campusAttendance.listSummaries),
);
router.put(
  '/summaries/:campusKey/:date',
  permissions.checkPermissions(FEATURE_PERMISSIONS.FILL_ATTENDANCE),
  wrapAsync(campusAttendance.upsertSummary),
);

export default router;
