import express from 'express';
import { protect, permit } from '../middleware/auth.middleware.ts';
import {
    createPlan,
    listPlans,
    updatePlan,
    deletePlan,
    getPlanHistory,
    mapPlanToInstitutions,
    getPlanInstitutionMappings,
    updateInstitutionSubscriptionVisibility,
} from '../controllers/subscriptionPlan.controller.ts';

const router = express.Router();

router.route('/')
    .post(protect, permit("Admin"), createPlan)
    .get(protect, listPlans);

router.get('/history', protect, getPlanHistory);

router.route('/:id/institutions')
    .get(protect, permit("Admin"), getPlanInstitutionMappings)
    .put(protect, permit("Admin"), mapPlanToInstitutions);

router.patch('/:id/institutions/:institutionId', protect, permit("Admin"), updateInstitutionSubscriptionVisibility);

router.route('/:id')
    .put(protect, permit("Admin"), updatePlan)
    .delete(protect, permit("Admin"), deletePlan);

export default router;
