"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.workflowTemplateChangeDraftFromWorkerDraft = workflowTemplateChangeDraftFromWorkerDraft;
exports.workflowTemplateChangeSetFromWorkerDraft = workflowTemplateChangeSetFromWorkerDraft;
exports.workflowTemplateChangeSetFromDraftFile = workflowTemplateChangeSetFromDraftFile;
exports.attachWorkflowTemplateUpdateBaseDigests = attachWorkflowTemplateUpdateBaseDigests;
exports.prepareWorkflowTemplateChangeSet = prepareWorkflowTemplateChangeSet;
exports.buildWorkflowTemplateCandidateSources = buildWorkflowTemplateCandidateSources;
exports.writePreparedWorkflowTemplateChangeSet = writePreparedWorkflowTemplateChangeSet;
exports.buildWorkflowTemplateChangeSetDraftFile = buildWorkflowTemplateChangeSetDraftFile;
exports.renderWorkflowTemplateChangeSetSummary = renderWorkflowTemplateChangeSetSummary;
exports.renderWorkflowTemplateChangeSetDraftReviewSummary = renderWorkflowTemplateChangeSetDraftReviewSummary;
// biome-ignore lint/nursery/noExcessiveLinesPerFile: Workflow template change-set conversion, validation, and review rendering stay grouped around one draft contract.
const branding_1 = require("../core/branding");
const catalog_1 = require("../i18n/catalog");
const template_registry_1 = require("../workflows/template-registry");
const workflow_template_command_support_1 = require("./workflow-template-command-support");
const workflow_template_draft_file_1 = require("./workflow-template-draft-file");
const workflow_template_update_mode_guard_1 = require("./workflow-template-update-mode-guard");
function workflowTemplateChangeDraftFromWorkerDraft(draft) {
    if (draft.action === "reuse_existing") {
        return {
            action: "reuse_existing",
            workflowTemplatePath: draft.targetPath,
            reason: draft.reason,
        };
    }
    if (draft.action === "update_existing") {
        return {
            action: "update_existing",
            targetWorkflowTemplatePath: draft.targetPath,
            workflowTemplatePath: draft.path,
            description: draft.description,
            requiredSkills: draft.requiredSkills,
            requiredMcp: draft.requiredMcp,
            targets: draft.targets,
            autoSelect: draft.autoSelect,
            body: draft.body,
            impactSummary: draft.impactSummary,
        };
    }
    return {
        action: "create_new",
        workflowTemplatePath: draft.path,
        description: draft.description,
        requiredSkills: draft.requiredSkills,
        requiredMcp: draft.requiredMcp,
        targets: draft.targets,
        autoSelect: draft.autoSelect,
        body: draft.body,
    };
}
function workflowTemplateChangeSetFromWorkerDraft(input) {
    const items = "items" in input.draft
        ? input.draft.items.map(workflowTemplateChangeDraftFromWorkerDraft)
        : [workflowTemplateChangeDraftFromWorkerDraft(input.draft)];
    return {
        command: input.command,
        templateSet: input.templateSet,
        ...(input.sourcePrompt !== undefined
            ? { sourcePrompt: input.sourcePrompt }
            : {}),
        ...(input.anchorPath !== undefined ? { anchorPath: input.anchorPath } : {}),
        items,
    };
}
function workflowTemplateChangeSetFromDraftFile(input) {
    if ("templateSet" in input.draftFile) {
        if (input.draftFile.command !== input.command) {
            throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.template.invalidDraftFile"));
        }
        if (input.command !== "delete" &&
            input.draftFile.items.some((item) => item.action === "delete_existing")) {
            throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.template.invalidDraftFile"));
        }
        return {
            command: input.draftFile.command,
            templateSet: true,
            ...(input.draftFile.sourcePrompt !== undefined
                ? { sourcePrompt: input.draftFile.sourcePrompt }
                : {}),
            ...(input.draftFile.anchorPath !== undefined
                ? { anchorPath: input.draftFile.anchorPath }
                : {}),
            items: input.draftFile.items.map(changeDraftFromDraftFileItem),
        };
    }
    if (input.draftFile.command !== input.command) {
        throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.template.invalidDraftFile"));
    }
    if (input.command === "update" && input.draftFile.mode !== "update") {
        throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.template.invalidDraftFile"));
    }
    return {
        command: input.command,
        templateSet: false,
        ...(input.draftFile.sourcePrompt !== undefined
            ? { sourcePrompt: input.draftFile.sourcePrompt }
            : {}),
        items: [changeDraftFromSingleDraftFile(input.draftFile)],
    };
}
function attachWorkflowTemplateUpdateBaseDigests(draft, catalog) {
    return {
        ...draft,
        items: draft.items.map((item) => {
            if ((item.action !== "update_existing" &&
                item.action !== "delete_existing") ||
                item.baseDigest !== undefined) {
                return item;
            }
            const targetTemplate = catalog.templateByPath.get(item.action === "update_existing"
                ? item.targetWorkflowTemplatePath
                : item.workflowTemplatePath);
            return targetTemplate === undefined
                ? item
                : { ...item, baseDigest: targetTemplate.digest };
        }),
    };
}
async function prepareWorkflowTemplateChangeSet(input) {
    const preparedItems = input.draft.items.map((item) => prepareWorkflowTemplateChangeDraft({
        draft: item,
        catalog: input.catalog,
        locale: input.locale,
    }));
    (0, workflow_template_update_mode_guard_1.ensureWorkflowTemplateUpdateModesAllowChanges)({
        draft: input.draft,
        catalog: input.catalog,
        preparedItems,
        locale: input.locale,
    });
    ensureNoDuplicatePreparedTemplatePaths(preparedItems);
    ensureTemplateMovesRequireTemplateSet({
        templateSet: input.draft.templateSet,
        preparedItems,
    });
    ensureTemplateSetAnchorIsRepresented({
        draft: input.draft,
        preparedItems,
        locale: input.locale,
    });
    await validatePreparedWorkflowTemplateChanges({
        preparedItems,
        templateSet: input.draft.templateSet,
        workflowTemplatesDirectory: input.workflowTemplatesDirectory,
        maxNestedWorkflowDepth: input.maxNestedWorkflowDepth,
        locale: input.locale,
    });
    return {
        command: input.draft.command,
        templateSet: input.draft.templateSet,
        ...(input.draft.sourcePrompt !== undefined
            ? { sourcePrompt: input.draft.sourcePrompt }
            : {}),
        ...(input.draft.anchorPath !== undefined
            ? { anchorPath: input.draft.anchorPath }
            : {}),
        items: preparedItems,
    };
}
async function validatePreparedWorkflowTemplateChanges(input) {
    const candidates = buildWorkflowTemplateCandidateSources(input.preparedItems);
    const deletedTemplatePaths = input.preparedItems.flatMap((item) => item.action === "delete_existing" ? [item.templatePath] : []);
    if (deletedTemplatePaths.length > 0) {
        await (0, workflow_template_command_support_1.validateWorkflowTemplateCandidateSet)({
            workflowTemplatesDirectory: input.workflowTemplatesDirectory,
            candidates,
            deletedTemplatePaths,
            maxNestedWorkflowDepth: input.maxNestedWorkflowDepth,
            locale: input.locale,
        });
        return;
    }
    if (candidates.length === 0) {
        return;
    }
    if (input.templateSet || candidates.length > 1) {
        await (0, workflow_template_command_support_1.validateWorkflowTemplateCandidateSet)({
            workflowTemplatesDirectory: input.workflowTemplatesDirectory,
            candidates,
            maxNestedWorkflowDepth: input.maxNestedWorkflowDepth,
            locale: input.locale,
        });
        return;
    }
    const [candidate] = candidates;
    if (candidate === undefined) {
        return;
    }
    const prepared = input.preparedItems.find((item) => item.action !== "reuse_existing");
    await (0, workflow_template_command_support_1.validateWorkflowTemplateCandidate)({
        workflowTemplatesDirectory: input.workflowTemplatesDirectory,
        templatePath: candidate.templatePath,
        source: candidate.source,
        ...(candidate.replacedTemplatePath !== undefined
            ? { replacedTemplatePath: candidate.replacedTemplatePath }
            : {}),
        maxNestedWorkflowDepth: input.maxNestedWorkflowDepth,
        locale: input.locale,
        scope: prepared?.action === "update_existing" ? "target-tree" : "catalog",
    });
}
function buildWorkflowTemplateCandidateSources(preparedItems) {
    const candidates = [];
    for (const item of preparedItems) {
        if (item.action === "reuse_existing" || item.action === "delete_existing") {
            continue;
        }
        const candidate = {
            templatePath: item.templatePath,
            source: item.source,
        };
        if (item.action === "update_existing" &&
            item.targetPath !== item.templatePath) {
            candidate.replacedTemplatePath = item.targetPath;
        }
        candidates.push(candidate);
    }
    return candidates;
}
async function writePreparedWorkflowTemplateChangeSet(input) {
    for (const item of input.prepared.items) {
        if (item.action !== "create_new") {
            continue;
        }
        await (0, workflow_template_command_support_1.writeNewWorkflowTemplateSource)(input.workflowTemplatesDirectory, item.templatePath, item.source, input.locale);
    }
    for (const item of input.prepared.items) {
        if (item.action !== "update_existing") {
            continue;
        }
        if (item.targetPath !== item.templatePath) {
            await (0, workflow_template_command_support_1.writeMovedWorkflowTemplateSource)(input.workflowTemplatesDirectory, item.targetPath, item.templatePath, item.source, input.locale);
            continue;
        }
        await (0, workflow_template_command_support_1.writeExistingWorkflowTemplateSource)(input.workflowTemplatesDirectory, item.templatePath, item.source);
    }
    for (const item of input.prepared.items) {
        if (item.action !== "delete_existing") {
            continue;
        }
        await (0, workflow_template_command_support_1.removeWorkflowTemplateSourceFile)(input.workflowTemplatesDirectory, item.templatePath);
    }
}
function buildWorkflowTemplateChangeSetDraftFile(input) {
    if (input.prepared.command !== "delete" &&
        !input.prepared.templateSet &&
        input.prepared.items.length === 1) {
        const [singleItem] = input.prepared.items;
        if (singleItem === undefined) {
            throw new Error("Workflow template draft file requires one item.");
        }
        return buildSingleWorkflowTemplateDraftFile({
            preparedAt: input.preparedAt,
            ...(input.prepared.sourcePrompt !== undefined
                ? { sourcePrompt: input.prepared.sourcePrompt }
                : {}),
            command: input.prepared.command,
            prepared: singleItem,
        });
    }
    return (0, workflow_template_draft_file_1.buildWorkflowTemplateDraftFile)({
        command: input.prepared.command,
        templateSet: true,
        preparedAt: input.preparedAt,
        ...(input.prepared.sourcePrompt !== undefined
            ? { sourcePrompt: input.prepared.sourcePrompt }
            : {}),
        ...(input.prepared.anchorPath !== undefined
            ? { anchorPath: input.prepared.anchorPath }
            : {}),
        items: input.prepared.items.map(draftFileItemFromPreparedChange),
    });
}
function renderWorkflowTemplateChangeSetSummary(input) {
    return input.prepared.items
        .map((item) => renderWorkflowTemplateChangeSummary(item, input.locale))
        .join("\n\n");
}
function renderWorkflowTemplateChangeSetDraftReviewSummary(input) {
    const lines = [
        input.prepared.templateSet
            ? (0, catalog_1.translate)(input.locale, "workflow.command.templateSet.draftReview.heading")
            : input.prepared.command === "update"
                ? (0, catalog_1.translate)(input.locale, "workflow.command.update.draftReview.heading")
                : (0, catalog_1.translate)(input.locale, "workflow.command.create.draftReview.heading"),
    ];
    for (const item of input.prepared.items) {
        lines.push("", ...renderWorkflowTemplateChangeDraftReviewLines(item, input.locale));
    }
    if (input.applyDraftPath !== undefined) {
        lines.push("", (0, catalog_1.translate)(input.locale, "workflow.command.template.draftReview.savedDraft", {
            value: input.applyDraftPath,
        }));
    }
    return lines.join("\n");
}
function prepareWorkflowTemplateChangeDraft(input) {
    const templatePath = (0, workflow_template_command_support_1.normalizeWorkflowTemplateCommandPath)(input.draft.workflowTemplatePath, input.locale);
    if (input.draft.action === "reuse_existing") {
        ensureWorkflowTemplateExists(input.catalog, templatePath, input.locale);
        return {
            action: "reuse_existing",
            templatePath,
            reason: input.draft.reason,
        };
    }
    if (input.draft.action === "delete_existing") {
        const currentTarget = ensureWorkflowTemplateExists(input.catalog, templatePath, input.locale);
        if (currentTarget.source !== "repository" ||
            (0, template_registry_1.isSystemWorkflowTemplatePath)(currentTarget.templatePath)) {
            throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.delete.systemBlocked", {
                templatePath: currentTarget.templatePath,
            }));
        }
        if (input.draft.baseDigest === undefined ||
            currentTarget.digest !== input.draft.baseDigest) {
            throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.update.digestConflict", {
                templatePath,
            }));
        }
        return {
            action: "delete_existing",
            templatePath,
            baseDigest: currentTarget.digest,
            reason: input.draft.reason,
        };
    }
    const content = (0, workflow_template_command_support_1.normalizeWorkflowTemplateContentSource)({
        description: input.draft.description,
        requiredSkills: input.draft.requiredSkills,
        requiredMcp: input.draft.requiredMcp,
        targets: input.draft.targets,
        autoSelect: input.draft.autoSelect,
        body: input.draft.body,
    }, input.locale, { bodyValidationOrder: "before-fields" });
    if (input.draft.action === "update_existing") {
        const targetPath = (0, workflow_template_command_support_1.normalizeWorkflowTemplateCommandPath)(input.draft.targetWorkflowTemplatePath, input.locale);
        const currentTarget = ensureWorkflowTemplateExists(input.catalog, targetPath, input.locale);
        if (templatePath !== targetPath) {
            (0, workflow_template_command_support_1.ensureWorkflowTemplateCreateTargetIsAvailable)(input.catalog, templatePath, input.locale);
        }
        if (input.draft.baseDigest === undefined ||
            currentTarget.digest !== input.draft.baseDigest) {
            throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.update.digestConflict", {
                templatePath: targetPath,
            }));
        }
        const source = (0, workflow_template_command_support_1.renderWorkflowTemplateSource)({
            workflowTemplatePath: templatePath,
            ...content,
            ...(currentTarget.metadata?.updateMode !== undefined
                ? { updateMode: currentTarget.metadata.updateMode }
                : {}),
        });
        return {
            action: "update_existing",
            targetPath,
            templatePath,
            source,
            ...content,
            baseDigest: currentTarget.digest,
            impactSummary: input.draft.impactSummary ?? null,
        };
    }
    (0, workflow_template_command_support_1.ensureWorkflowTemplateCreateTargetIsAvailable)(input.catalog, templatePath, input.locale);
    const source = (0, workflow_template_command_support_1.renderWorkflowTemplateSource)({
        workflowTemplatePath: templatePath,
        ...content,
        updateMode: template_registry_1.DEFAULT_WORKFLOW_TEMPLATE_UPDATE_MODE,
    });
    return {
        action: "create_new",
        templatePath,
        source,
        ...content,
    };
}
function ensureTemplateSetAnchorIsRepresented(input) {
    if (input.draft.command !== "update" || input.draft.templateSet !== true) {
        return;
    }
    if (input.draft.anchorPath === undefined) {
        throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.templateSet.missingAnchorPath"));
    }
    const anchorPath = (0, workflow_template_command_support_1.normalizeWorkflowTemplateCommandPath)(input.draft.anchorPath, input.locale);
    const anchorItem = input.preparedItems.find((item) => (item.action === "update_existing"
        ? item.targetPath === anchorPath
        : item.templatePath === anchorPath) &&
        (item.action === "update_existing" || item.action === "reuse_existing"));
    if (anchorItem === undefined) {
        throw new Error((0, catalog_1.translate)(input.locale, "workflow.command.templateSet.missingAnchorItem", {
            templatePath: anchorPath,
        }));
    }
}
function ensureWorkflowTemplateExists(catalog, templatePath, locale) {
    const template = catalog.templateByPath.get(templatePath);
    if (template === undefined) {
        throw new Error((0, catalog_1.translate)(locale, "workflow.command.update.missingPath", {
            templatePath,
        }));
    }
    return template;
}
function ensureNoDuplicatePreparedTemplatePaths(items) {
    const seen = new Set();
    const updateTargets = new Set();
    for (const item of items) {
        if (seen.has(item.templatePath)) {
            throw new Error(`Workflow template \`${item.templatePath}\` appears more than once in the draft.`);
        }
        seen.add(item.templatePath);
        if (item.action !== "update_existing") {
            continue;
        }
        if (updateTargets.has(item.targetPath)) {
            throw new Error(`Workflow template update target \`${item.targetPath}\` appears more than once in the draft.`);
        }
        updateTargets.add(item.targetPath);
    }
}
function ensureTemplateMovesRequireTemplateSet(input) {
    if (input.templateSet) {
        return;
    }
    const movedItem = input.preparedItems.find((item) => item.action === "update_existing" &&
        item.targetPath !== item.templatePath);
    if (movedItem === undefined || movedItem.action !== "update_existing") {
        return;
    }
    throw new Error(`Workflow template update can move \`${movedItem.targetPath}\` to \`${movedItem.templatePath}\` only in template-set mode.`);
}
function changeDraftFromSingleDraftFile(draftFile) {
    if (draftFile.mode === "reuse") {
        return {
            action: "reuse_existing",
            workflowTemplatePath: draftFile.path,
            reason: draftFile.reason,
        };
    }
    if (draftFile.mode === "update") {
        return {
            action: "update_existing",
            targetWorkflowTemplatePath: draftFile.path,
            workflowTemplatePath: draftFile.path,
            description: draftFile.description,
            requiredSkills: draftFile.requiredSkills,
            requiredMcp: draftFile.requiredMcp,
            targets: draftFile.targets,
            autoSelect: draftFile.autoSelect,
            body: draftFile.body,
            baseDigest: draftFile.baseDigest,
            impactSummary: draftFile.impactSummary ?? null,
        };
    }
    return {
        action: "create_new",
        workflowTemplatePath: draftFile.path,
        description: draftFile.description,
        requiredSkills: draftFile.requiredSkills,
        requiredMcp: draftFile.requiredMcp,
        targets: draftFile.targets,
        autoSelect: draftFile.autoSelect,
        body: draftFile.body,
    };
}
function changeDraftFromDraftFileItem(item) {
    if (item.action === "reuse_existing") {
        return {
            action: "reuse_existing",
            workflowTemplatePath: item.targetPath,
            reason: item.reason,
        };
    }
    if (item.action === "delete_existing") {
        return {
            action: "delete_existing",
            workflowTemplatePath: item.targetPath,
            baseDigest: item.baseDigest,
            reason: item.reason,
        };
    }
    if (item.action === "update_existing") {
        return {
            action: "update_existing",
            targetWorkflowTemplatePath: item.targetPath,
            workflowTemplatePath: item.path,
            description: item.description,
            requiredSkills: item.requiredSkills,
            requiredMcp: item.requiredMcp,
            targets: item.targets,
            autoSelect: item.autoSelect,
            body: item.body,
            baseDigest: item.baseDigest,
            impactSummary: item.impactSummary ?? null,
        };
    }
    return {
        action: "create_new",
        workflowTemplatePath: item.path,
        description: item.description,
        requiredSkills: item.requiredSkills,
        requiredMcp: item.requiredMcp,
        targets: item.targets,
        autoSelect: item.autoSelect,
        body: item.body,
    };
}
function buildSingleWorkflowTemplateDraftFile(input) {
    if (input.prepared.action === "delete_existing") {
        throw new Error("Workflow delete drafts must use template-set draft files.");
    }
    if (input.prepared.action === "reuse_existing") {
        return (0, workflow_template_draft_file_1.buildWorkflowTemplateDraftFile)({
            command: input.command,
            mode: "reuse",
            preparedAt: input.preparedAt,
            ...(input.sourcePrompt !== undefined
                ? { sourcePrompt: input.sourcePrompt }
                : {}),
            path: input.prepared.templatePath,
            reason: input.prepared.reason,
        });
    }
    if (input.prepared.action === "update_existing") {
        return (0, workflow_template_draft_file_1.buildWorkflowTemplateDraftFile)({
            command: input.command,
            mode: "update",
            preparedAt: input.preparedAt,
            ...(input.sourcePrompt !== undefined
                ? { sourcePrompt: input.sourcePrompt }
                : {}),
            path: input.prepared.templatePath,
            description: input.prepared.description,
            requiredSkills: input.prepared.requiredSkills,
            requiredMcp: input.prepared.requiredMcp,
            targets: input.prepared.targets,
            autoSelect: input.prepared.autoSelect,
            body: input.prepared.body,
            baseDigest: input.prepared.baseDigest,
            impactSummary: input.prepared.impactSummary,
        });
    }
    return (0, workflow_template_draft_file_1.buildWorkflowTemplateDraftFile)({
        command: input.command,
        mode: "create",
        preparedAt: input.preparedAt,
        ...(input.sourcePrompt !== undefined
            ? { sourcePrompt: input.sourcePrompt }
            : {}),
        path: input.prepared.templatePath,
        description: input.prepared.description,
        requiredSkills: input.prepared.requiredSkills,
        requiredMcp: input.prepared.requiredMcp,
        targets: input.prepared.targets,
        autoSelect: input.prepared.autoSelect,
        body: input.prepared.body,
    });
}
function draftFileItemFromPreparedChange(item) {
    if (item.action === "reuse_existing") {
        return {
            action: "reuse_existing",
            targetPath: item.templatePath,
            reason: item.reason,
        };
    }
    if (item.action === "delete_existing") {
        return {
            action: "delete_existing",
            targetPath: item.templatePath,
            baseDigest: item.baseDigest,
            reason: item.reason,
        };
    }
    if (item.action === "update_existing") {
        return {
            action: "update_existing",
            targetPath: item.targetPath,
            path: item.templatePath,
            description: item.description,
            requiredSkills: item.requiredSkills,
            requiredMcp: item.requiredMcp,
            targets: item.targets,
            autoSelect: item.autoSelect,
            body: item.body,
            baseDigest: item.baseDigest,
            impactSummary: item.impactSummary,
        };
    }
    return {
        action: "create_new",
        path: item.templatePath,
        description: item.description,
        requiredSkills: item.requiredSkills,
        requiredMcp: item.requiredMcp,
        targets: item.targets,
        autoSelect: item.autoSelect,
        body: item.body,
    };
}
function renderWorkflowTemplateChangeSummary(item, locale) {
    if (item.action === "reuse_existing") {
        return [
            (0, catalog_1.translate)(locale, "workflow.command.create.reused", {
                templatePath: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.create.path", {
                value: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.create.reuseReason", {
                value: item.reason,
            }),
        ].join("\n");
    }
    if (item.action === "delete_existing") {
        return [
            (0, catalog_1.translate)(locale, "workflow.command.delete.deleted", {
                templatePath: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.create.path", {
                value: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.delete.reason", {
                value: item.reason,
            }),
        ].join("\n");
    }
    const updateOrCreate = item.action === "update_existing"
        ? [
            (0, catalog_1.translate)(locale, "workflow.command.update.updated", {
                templatePath: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.update.path", {
                value: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.update.file", {
                value: `${branding_1.WORKFLOW_TEMPLATES_DIRECTORY}/${item.templatePath}`,
            }),
        ]
        : [
            (0, catalog_1.translate)(locale, "workflow.command.create.created", {
                templatePath: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.create.path", {
                value: item.templatePath,
            }),
            (0, catalog_1.translate)(locale, "workflow.command.create.file", {
                value: `${branding_1.WORKFLOW_TEMPLATES_DIRECTORY}/${item.templatePath}`,
            }),
        ];
    return updateOrCreate.join("\n");
}
function renderWorkflowTemplateChangeDraftReviewLines(item, locale) {
    const lines = [
        (0, catalog_1.translate)(locale, "workflow.command.template.draftReview.action", {
            value: item.action,
        }),
        (0, catalog_1.translate)(locale, "workflow.command.create.path", {
            value: item.templatePath,
        }),
    ];
    if (item.action === "reuse_existing") {
        lines.push((0, catalog_1.translate)(locale, "workflow.command.create.reuseReason", {
            value: item.reason,
        }));
        return lines;
    }
    if (item.action === "delete_existing") {
        lines.push((0, catalog_1.translate)(locale, "workflow.command.template.draftReview.baseDigest", {
            value: item.baseDigest,
        }), (0, catalog_1.translate)(locale, "workflow.command.delete.reason", {
            value: item.reason,
        }));
        return lines;
    }
    lines.push((0, catalog_1.translate)(locale, "workflow.command.template.draftReview.description", {
        value: item.description ?? (0, catalog_1.translate)(locale, "workflow.runContext.none"),
    }), (0, catalog_1.translate)(locale, "workflow.command.template.draftReview.requiredSkills", {
        value: item.requiredSkills.length === 0
            ? (0, catalog_1.translate)(locale, "workflow.runContext.none")
            : item.requiredSkills.join(", "),
    }), (0, catalog_1.translate)(locale, "workflow.command.template.draftReview.requiredMcp", {
        value: item.requiredMcp.length === 0
            ? (0, catalog_1.translate)(locale, "workflow.runContext.none")
            : item.requiredMcp.join(", "),
    }), (0, catalog_1.translate)(locale, "workflow.command.template.draftReview.targets", {
        value: item.targets.join(", "),
    }), (0, catalog_1.translate)(locale, "workflow.command.template.draftReview.autoSelect", {
        value: item.autoSelect ? "yes" : "no",
    }));
    if (item.action === "update_existing") {
        lines.push((0, catalog_1.translate)(locale, "workflow.command.template.draftReview.baseDigest", {
            value: item.baseDigest,
        }));
        if (item.impactSummary !== null) {
            lines.push((0, catalog_1.translate)(locale, "workflow.command.template.draftReview.impact", {
                value: item.impactSummary,
            }));
        }
    }
    lines.push("", (0, catalog_1.translate)(locale, "workflow.command.template.draftReview.body"), item.body);
    return lines;
}
