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/parent-messages:
 *   get:
 *     tags: [Communications]
 *     summary: List parent messages
 *     description: Requires `READ_PARENT_COMM`.
 *     responses:
 *       200:
 *         description: Parent messages.
 *         content:
 *           application/json:
 *             schema: { $ref: '#/components/schemas/ListResponse' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   post:
 *     tags: [Communications]
 *     summary: Send a parent message (manager-only; service-gated)
 *     responses:
 *       200: { description: Sent. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /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(
  '/parent-messages',
  permissions.checkPermissions(FEATURE_PERMISSIONS.READ_PARENT_COMM),
  wrapAsync(communications.listParentMessages),
);
router.post('/parent-messages', wrapAsync(communications.createParentMessage));
router.get(
  '/events',
  permissions.checkPermissions(FEATURE_PERMISSIONS.READ_INTERNAL_COMM),
  wrapAsync(communications.listEvents),
);
router.post('/events', wrapAsync(communications.createEvent));

export default router;
