"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildScheduledRunSyncPlanSpec = buildScheduledRunSyncPlanSpec;
const types_1 = require("../../platform/workflow-state/types");
const publisher_1 = require("../../workflows/publisher");
const scheduled_run_1 = require("../../workflows/scheduled-run");
const config_publish_spec_support_1 = require("./config-publish-spec-support");
function buildScheduledRunSyncPlanSpec(input) {
    if (!(0, scheduled_run_1.hasActiveScheduledRun)(input.workflowState)) {
        return {
            kind: "noop",
            decisionKind: "scheduled_sync",
            targetIssueId: input.issue.id,
        };
    }
    const nextWorkflowState = (0, scheduled_run_1.clearScheduledRun)(input.workflowState);
    const nextSnapshot = {
        status: types_1.WORKFLOW_STATUSES.aiReady,
        rules: [...input.issue.workflowState.rules],
    };
    return (0, config_publish_spec_support_1.buildServiceRuntimeProjectedPublishSpec)({
        decisionKind: "scheduled_sync",
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: nextWorkflowState,
        scannedInputCursor: null,
        commentCursorPolicyMode: publisher_1.WORKFLOW_COMMENT_CURSOR_POLICY_MODES.preserve,
        workflowLabels: input.workflowLabels,
        nextWorkflowSnapshot: nextSnapshot,
        previousWorkflowState: input.workflowState,
        nextWorkflowState,
        previousNeedsHumanReason: input.currentNeedsHumanReason,
        nextNeedsHumanReason: null,
    });
}
