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

const router = express.Router();

/**
 * @openapi
 * /api/communications/events:
 *   get:
 *     tags: [Communications]
 *     summary: List internal communication events
 *     description: Requires `READ_INTERNAL_COMM`.
 *     responses:
 *       200:
 *         description: Events.
 *         content:
 *           application/json:
 *             schema: { $ref: '#/components/schemas/ListResponse' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   post:
 *     tags: [Communications]
 *     summary: Create an internal event (manager-only; service-gated)
 *     responses:
 *       200: { description: Created. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
router.get(
  '/events',
  permissions.checkPermissions(FEATURE_PERMISSIONS.READ_INTERNAL_COMM),
  wrapAsync(communications.listEvents),
);
router.post('/events', wrapAsync(communications.createEvent));
router.patch('/events/:id', wrapAsync(communications.updateEvent));
router.delete('/events/:id', wrapAsync(communications.deleteEvent));
router.post('/events/:id/cancel', wrapAsync(communications.cancelEvent));

export default router;
