"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveWorkflowFollowupState = resolveWorkflowFollowupState;
exports.resolveWorkflowFollowupConfigFromPatch = resolveWorkflowFollowupConfigFromPatch;
function resolveWorkflowFollowupState(input) {
    if (input.currentFollowup !== undefined && input.refreshPolicy !== true) {
        return input.currentFollowup;
    }
    const baseFollowup = input.currentFollowup ??
        (input.currentStateExists === true
            ? {
                proposalPolicy: "off",
                proposalApproval: input.config.proposalApproval,
            }
            : {
                proposalPolicy: input.config.proposalPolicy,
                proposalApproval: input.config.proposalApproval,
            });
    return {
        ...baseFollowup,
        proposalPolicy: input.config.proposalPolicy,
        proposalApproval: input.config.proposalApproval,
    };
}
function resolveWorkflowFollowupConfigFromPatch(baseConfig, patch) {
    const config = { ...baseConfig };
    for (const entry of patch?.entries ?? []) {
        if (entry.path === "followup.proposalPolicy") {
            config.proposalPolicy =
                entry.op === "inherit"
                    ? baseConfig.proposalPolicy
                    : entry.value;
        }
        if (entry.path === "followup.proposalApproval") {
            config.proposalApproval =
                entry.op === "inherit"
                    ? baseConfig.proposalApproval
                    : entry.value;
        }
    }
    return config;
}
