"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildWorkflowTemplateCandidates = buildWorkflowTemplateCandidates;
exports.findAutoSelectableWorkflowTemplate = findAutoSelectableWorkflowTemplate;
const template_registry_1 = require("./template-registry");
function buildWorkflowTemplateCandidates(catalog, options = {}) {
    return catalog.templates
        .filter((template) => workflowTemplateMatchesCandidateOptions(template, options))
        .map(toWorkflowTemplateCandidate);
}
function findAutoSelectableWorkflowTemplate(input) {
    const target = input.target;
    return (input.catalog.templates.find((template) => workflowTemplateMatchesCandidateOptions(template, {
        target,
        autoOnly: true,
    })) ?? null);
}
function workflowTemplateMatchesCandidateOptions(template, options) {
    const targetsRequestedSurface = options.target === undefined
        ? true
        : (0, template_registry_1.resolveWorkflowTemplateRecordTargets)(template).includes(options.target);
    return (targetsRequestedSurface &&
        (options.includeSystem === true || !template.system) &&
        (options.autoOnly !== true || template.autoSelect !== false));
}
function toWorkflowTemplateCandidate(template) {
    return {
        templatePath: template.templatePath,
        system: template.system,
        source: template.source,
        targets: (0, template_registry_1.resolveWorkflowTemplateRecordTargets)(template),
        autoSelect: template.autoSelect ?? true,
        updateMode: template.updateMode ?? "flexible",
        description: template.metadata?.description ?? null,
        requiredSkills: template.metadata?.requiredSkills ?? [],
        requiredMcp: template.metadata?.requiredMcp ?? [],
    };
}
