import express from 'express';
import { authenticate } from '../middleware/authMiddleware.js';
import { authorize } from '../middleware/authorizationMiddleware.js';
import clubCommunicationController from '../controllers/clubCommunicationController.js';

const router = express.Router();

router.use(authenticate);

router.get('/:clubId', authorize('communication', 'read'), clubCommunicationController.list);
router.post('/:clubId/threads', authorize('communication', 'write'), clubCommunicationController.createThread);
router.put('/:clubId/threads/:threadId', authorize('communication', 'write'), clubCommunicationController.updateThread);
router.delete('/:clubId/threads/:threadId', authorize('communication', 'write'), clubCommunicationController.deleteThread);
router.post('/:clubId/threads/:threadId/messages', authorize('communication', 'write'), clubCommunicationController.addMessage);
router.patch('/:clubId/threads/:threadId/send', authorize('communication', 'write'), clubCommunicationController.sendThread);

router.post('/:clubId/groups', authorize('communication', 'write'), clubCommunicationController.createGroup);
router.put('/:clubId/groups/:groupId', authorize('communication', 'write'), clubCommunicationController.updateGroup);
router.delete('/:clubId/groups/:groupId', authorize('communication', 'write'), clubCommunicationController.deleteGroup);
router.post('/:clubId/templates', authorize('communication', 'write'), clubCommunicationController.createTemplate);
router.put('/:clubId/templates/:templateId', authorize('communication', 'write'), clubCommunicationController.updateTemplate);
router.delete('/:clubId/templates/:templateId', authorize('communication', 'write'), clubCommunicationController.deleteTemplate);

export default router;
