"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const auth_middleware_1 = require("../../../middleware/auth.middleware");
const rbac_middleware_1 = require("../../../middleware/rbac.middleware");
const validate_1 = require("../../../middleware/validate");
const shift_series_service_1 = require("./shift-series.service");
const shift_series_schemas_1 = require("./shift-series.schemas");
const roles_1 = require("../../../utils/roles");
const router = (0, express_1.Router)();
// All routes require admin role
router.use(auth_middleware_1.authenticate, (0, rbac_middleware_1.requireRole)(...roles_1.SCHEDULING_ROLES));
// Create series
router.post('/', (0, validate_1.validate)(shift_series_schemas_1.createShiftSeriesSchema), async (req, res, next) => {
    try {
        const result = await shift_series_service_1.ShiftSeriesService.createSeries(req.body, req.user?.id);
        res.json(result);
    }
    catch (error) {
        next(error);
    }
});
// Get series shift count
router.get('/:id/count', async (req, res, next) => {
    try {
        const count = await shift_series_service_1.ShiftSeriesService.getShiftCount(req.params.id);
        res.json({ count });
    }
    catch (error) {
        next(error);
    }
});
// Get series
router.get('/:id', async (req, res, next) => {
    try {
        const series = await shift_series_service_1.ShiftSeriesService.getSeries(req.params.id);
        res.json({ series });
    }
    catch (error) {
        next(error);
    }
});
// Update series
router.put('/:id', (0, validate_1.validate)(shift_series_schemas_1.updateShiftSeriesSchema), async (req, res, next) => {
    try {
        const series = await shift_series_service_1.ShiftSeriesService.updateSeries(req.params.id, req.body);
        res.json({ series });
    }
    catch (error) {
        next(error);
    }
});
// Delete series
router.delete('/:id', async (req, res, next) => {
    try {
        await shift_series_service_1.ShiftSeriesService.deleteSeries(req.params.id);
        res.json({ success: true });
    }
    catch (error) {
        next(error);
    }
});
exports.default = router;
//# sourceMappingURL=shift-series.routes.js.map