"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildServiceRuntimeWorkflowProjection = buildServiceRuntimeWorkflowProjection;
exports.buildServiceRuntimePublishSpec = buildServiceRuntimePublishSpec;
exports.buildServiceRuntimeProjectedPublishSpec = buildServiceRuntimeProjectedPublishSpec;
exports.buildServiceRuntimeFeedbackPublishSpec = buildServiceRuntimeFeedbackPublishSpec;
const workflow_projection_support_1 = require("../../workflows/workflow-projection-support");
function buildServiceRuntimeWorkflowProjection(input) {
    return (0, workflow_projection_support_1.buildWorkflowProjectionWithAuxiliaryLabels)({
        workflowLabels: input.workflowLabels,
        previous: input.issue.workflowState,
        next: input.next,
        previousWorkflowState: input.previousWorkflowState,
        nextWorkflowState: input.nextWorkflowState,
        previousNeedsHumanReason: input.previousNeedsHumanReason,
        nextNeedsHumanReason: input.nextNeedsHumanReason,
    });
}
function buildServiceRuntimePublishSpec(input) {
    const planSpec = {
        kind: "publish_spec",
        decisionKind: input.decisionKind,
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: input.workflowState,
        scannedInputCursor: input.scannedInputCursor,
    };
    if (input.forcePublish !== undefined) {
        planSpec.forcePublish = input.forcePublish;
    }
    if (input.appendCanonicalWorkflowStateComment !== undefined) {
        planSpec.appendCanonicalWorkflowStateComment =
            input.appendCanonicalWorkflowStateComment;
    }
    if (input.commentCursorPolicyMode !== undefined) {
        planSpec.commentCursorPolicyMode = input.commentCursorPolicyMode;
    }
    if (input.visibleUpdate !== undefined) {
        planSpec.visibleUpdate = input.visibleUpdate;
    }
    if (input.visibleUpdateDedupeCursor !== undefined) {
        planSpec.visibleUpdateDedupeCursor = input.visibleUpdateDedupeCursor;
    }
    if (input.publishPrecondition !== undefined) {
        planSpec.publishPrecondition = input.publishPrecondition;
    }
    if (input.invalidWorkflowStatePolicy !== undefined) {
        planSpec.invalidWorkflowStatePolicy = input.invalidWorkflowStatePolicy;
    }
    if (input.workflowProjection !== undefined) {
        planSpec.workflowProjection = input.workflowProjection;
    }
    return planSpec;
}
function buildServiceRuntimeProjectedPublishSpec(input) {
    const workflowProjection = buildServiceRuntimeWorkflowProjection({
        issue: input.issue,
        workflowLabels: input.workflowLabels,
        next: input.nextWorkflowSnapshot,
        previousWorkflowState: input.previousWorkflowState,
        nextWorkflowState: input.nextWorkflowState,
        previousNeedsHumanReason: input.previousNeedsHumanReason,
        nextNeedsHumanReason: input.nextNeedsHumanReason,
    });
    return buildServiceRuntimePublishSpec({
        decisionKind: input.decisionKind,
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: input.workflowState,
        appendCanonicalWorkflowStateComment: input.appendCanonicalWorkflowStateComment,
        scannedInputCursor: input.scannedInputCursor,
        commentCursorPolicyMode: input.commentCursorPolicyMode,
        visibleUpdate: input.visibleUpdate,
        visibleUpdateDedupeCursor: input.visibleUpdateDedupeCursor,
        publishPrecondition: input.publishPrecondition,
        invalidWorkflowStatePolicy: input.invalidWorkflowStatePolicy,
        workflowProjection,
    });
}
function buildServiceRuntimeFeedbackPublishSpec(input) {
    const visibleUpdate = {
        kind: "feedback",
        summary: input.summary,
    };
    if (input.next !== undefined) {
        visibleUpdate.next = input.next;
    }
    return buildServiceRuntimePublishSpec({
        decisionKind: input.decisionKind,
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: input.workflowState,
        appendCanonicalWorkflowStateComment: input.appendCanonicalWorkflowStateComment,
        scannedInputCursor: input.scannedInputCursor,
        commentCursorPolicyMode: input.commentCursorPolicyMode,
        visibleUpdate,
        visibleUpdateDedupeCursor: input.visibleUpdateDedupeCursor,
        publishPrecondition: input.publishPrecondition,
        workflowProjection: input.workflowProjection,
    });
}
