const SCOPE_LABELS = {
    app: "application",
    org: "organization",
    user: "personal",
    integration: "integration",
};
export function buildKnowledgeFeedbackMessage(approved, allCandidates, selectedIndices, outcomes) {
    if (!approved || selectedIndices.length === 0) {
        const names = allCandidates.map((c) => `"${c.name}"`).join(", ");
        return (`The user declined to save the proposed knowledge ` +
            `(${names}). Do not re-suggest unless the user asks.`);
    }
    const selectedSet = new Set(selectedIndices);
    const outcomeLines = [];
    for (const outcome of outcomes) {
        const scopeLabel = SCOPE_LABELS[outcome.scope] ?? outcome.scope;
        const statusLabel = outcome.status === "created_remote" ? "created" : outcome.status;
        let line = `- "${outcome.factName}": ${statusLabel} (${scopeLabel} scope)`;
        if (outcome.status === "failed" && outcome.reason) {
            line += ` — ${outcome.reason}`;
        }
        outcomeLines.push(line);
    }
    const rejectedCandidates = allCandidates.filter((_, i) => !selectedSet.has(i));
    for (const rejected of rejectedCandidates) {
        outcomeLines.push(`- "${rejected.name}": not selected by user`);
    }
    const totalProposed = allCandidates.length;
    const savedCount = outcomes.filter((o) => o.status === "created" ||
        o.status === "updated" ||
        o.status === "deleted" ||
        o.status === "created_remote").length;
    const failedCount = outcomes.filter((o) => o.status === "failed").length;
    const header = savedCount === totalProposed
        ? `The user approved saving ${savedCount} knowledge ${savedCount === 1 ? "entry" : "entries"}:`
        : `The user saved ${savedCount} of ${totalProposed} proposed knowledge ${totalProposed === 1 ? "entry" : "entries"}:`;
    const parts = [header, ...outcomeLines];
    if (rejectedCandidates.length > 0) {
        const names = rejectedCandidates.map((c) => `"${c.name}"`).join(", ");
        parts.push(`\nThe user chose not to save ${names}. Do not re-suggest unless they ask.`);
    }
    if (failedCount > 0) {
        parts.push(`\n${failedCount} ${failedCount === 1 ? "entry" : "entries"} failed to save.`);
    }
    return parts.join("\n");
}
//# sourceMappingURL=build-knowledge-feedback-message.js.map