"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateFollowupRecommendationFields = validateFollowupRecommendationFields;
const constants_1 = require("./constants");
const types_1 = require("./types");
const validation_issues_1 = require("./validation-issues");
function validateFollowupRecommendationFields(decision, workflow, decisionMode, context) {
    const proposalPolicy = workflow?.state?.followup?.proposalPolicy ?? "off";
    const isClosingProceed = isClosingProceedWorkflowDecision(decision, decisionMode);
    if (proposalPolicy !== "off" &&
        isClosingProceed &&
        decision.followupRecommendation === undefined) {
        (0, validation_issues_1.addWorkerZodValidationIssue)(context, {
            path: ["followupRecommendation"],
            message: "followupRecommendation is required when workflow.state.followup.proposalPolicy is not off and workflow_closing is completing.",
        });
        return;
    }
    if (decision.followupRecommendation === undefined) {
        return;
    }
    if (isClosingProceed) {
        return;
    }
    (0, validation_issues_1.addWorkerZodValidationIssue)(context, {
        path: ["followupRecommendation"],
        message: "followupRecommendation is only allowed when workflow_closing is completing with outcome proceed.",
    });
}
function isClosingProceedWorkflowDecision(decision, decisionMode) {
    return (decision.outcome === constants_1.WORKER_OUTCOMES.proceed &&
        decision.continuation === undefined &&
        decisionMode === types_1.WORKER_RUN_MODES.workflowClosing);
}
