"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkRequiredCapabilityWorkerIntersection = checkRequiredCapabilityWorkerIntersection;
exports.formatRequiredCapabilityWorkerIntersectionReport = formatRequiredCapabilityWorkerIntersectionReport;
const catalog_1 = require("../i18n/catalog");
function checkRequiredCapabilityWorkerIntersection(input) {
    const skillRefs = input.skillReport.skillRefs;
    const mcpRefs = input.mcpReport.mcpRefs;
    if (skillRefs.length === 0 ||
        mcpRefs.length === 0 ||
        !input.skillReport.ok ||
        !input.mcpReport.ok) {
        return {
            ok: true,
            skillRefs,
            mcpRefs,
            runnableWorkers: intersectWorkers(input.skillReport.runnableWorkers, input.mcpReport.runnableWorkers),
        };
    }
    const runnableWorkers = intersectWorkers(input.skillReport.runnableWorkers, input.mcpReport.runnableWorkers);
    return {
        ok: runnableWorkers.length > 0,
        skillRefs,
        mcpRefs,
        runnableWorkers,
    };
}
function formatRequiredCapabilityWorkerIntersectionReport(input) {
    const { report, locale } = input;
    if (report.ok) {
        return report.skillRefs.length === 0 || report.mcpRefs.length === 0
            ? (0, catalog_1.translate)(locale, "workflow.requiredCapabilityIntersection.report.none")
            : (0, catalog_1.translate)(locale, "workflow.requiredCapabilityIntersection.report.available", {
                workers: report.runnableWorkers.join(", "),
            });
    }
    return [
        (0, catalog_1.translate)(locale, "workflow.requiredCapabilityIntersection.report.missing"),
        (0, catalog_1.translate)(locale, "workflow.requiredCapabilityIntersection.report.skills", {
            skillRefs: report.skillRefs.join(", "),
        }),
        (0, catalog_1.translate)(locale, "workflow.requiredCapabilityIntersection.report.mcp", {
            mcpRefs: report.mcpRefs.join(", "),
        }),
    ].join("\n");
}
function intersectWorkers(left, right) {
    const rightSet = new Set(right);
    return [...new Set(left)].filter((worker) => rightSet.has(worker)).sort();
}
