"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerSingleRoutes = registerSingleRoutes;
const api = __importStar(require("../../api/escalations"));
function registerSingleRoutes(router) {
    /**
     * PATCH /api/escalations/:id/escalate
     * Reassign an escalation to a different role.
     * Body: { targetRole: string }
     */
    router.patch('/:id/escalate', async (req, res) => {
        const result = await api.escalateToRole({ id: req.params.id, targetRole: req.body?.targetRole }, req.auth);
        res.status(result.status).json(result.data ?? { error: result.error });
    });
    /**
     * GET /api/escalations/by-workflow/:workflowId
     * List escalations linked to a specific workflow.
     */
    router.get('/by-workflow/:workflowId', async (req, res) => {
        const result = await api.getEscalationsByWorkflowId({
            workflowId: req.params.workflowId,
        });
        res.status(result.status).json(result.data ?? { error: result.error });
    });
    // -- Parameterized routes (must come after literal paths) --
    /**
     * GET /api/escalations/:id
     * Get a single escalation by ID.
     * RBAC: superadmin sees all; others must hold the escalation's role.
     */
    router.get('/:id', async (req, res) => {
        const result = await api.getEscalation({ id: req.params.id }, req.auth);
        res.status(result.status).json(result.data ?? { error: result.error });
    });
    /**
     * POST /api/escalations/:id/claim
     * Claim an escalation. userId comes from auth token.
     * Body: { durationMinutes?: number }
     */
    router.post('/:id/claim', async (req, res) => {
        const result = await api.claimEscalation({ id: req.params.id, durationMinutes: req.body?.durationMinutes }, req.auth);
        res.status(result.status).json(result.data ?? { error: result.error });
    });
    /**
     * POST /api/escalations/:id/release
     * Release a claimed escalation back to the available pool.
     * Only the assigned user may release their own claim.
     */
    router.post('/:id/release', async (req, res) => {
        const result = await api.releaseEscalation({ id: req.params.id }, req.auth);
        res.status(result.status).json(result.data ?? { error: result.error });
    });
}
