"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.patch = void 0;
function renameResultFields(value) {
    if (Array.isArray(value)) {
        return value.map((entry) => renameResultFields(entry));
    }
    if (value === null || typeof value !== "object") {
        return value;
    }
    const next = Object.fromEntries(Object.entries(value).map(([key, entry]) => [
        key,
        renameResultFields(entry),
    ]));
    if (Object.hasOwn(next, "outcome") &&
        Object.hasOwn(next, "summary") &&
        (Object.hasOwn(next, "evidence") || Object.hasOwn(next, "humanComment"))) {
        Reflect.set(next, "resultSummary", Reflect.get(next, "summary"));
        Reflect.deleteProperty(next, "summary");
    }
    return next;
}
exports.patch = {
    version: 14,
    changes: [
        {
            op: "custom",
            name: "rename-result-fields",
            apply: (state) => renameResultFields(state),
        },
    ],
};
