"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveVariantPreviewPort = void 0;
/**
 * Validate a requested preview port against the active MCP variant session.
 */
const resolveVariantPreviewPort = (rawPort, sessionGate) => {
    if (rawPort === null || rawPort === undefined) {
        return { ok: true, port: null };
    }
    if (!Number.isInteger(rawPort) || rawPort <= 0) {
        return { ok: false, status: 400, error: 'Invalid preview port' };
    }
    if (!sessionGate.isActive()) {
        return { ok: false, status: 400, error: 'No active MCP session' };
    }
    const port = rawPort;
    if (!sessionGate.isVariantPortAllowed(port)) {
        return {
            ok: false,
            status: 403,
            error: `Preview port ${port} is not registered for this variant session`,
        };
    }
    return { ok: true, port };
};
exports.resolveVariantPreviewPort = resolveVariantPreviewPort;
//# sourceMappingURL=variantPreviewPort.js.map