"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isWorkflowChildState = isWorkflowChildState;
exports.isWorkflowParentState = isWorkflowParentState;
exports.resolveWorkflowChildIssueSteps = resolveWorkflowChildIssueSteps;
exports.hasLinkedWorkflowChildIssueStep = hasLinkedWorkflowChildIssueStep;
const types_1 = require("../workflows/types");
const issue_ref_1 = require("../workflows/issue-ref");
function isWorkflowChildState(workflowState) {
    return ((0, issue_ref_1.normalizeWorkflowIssueDisplayRef)(workflowState?.parentLink?.parentRef) !==
        null);
}
function isWorkflowParentState(workflowState) {
    return (isRecurringParentState(workflowState) ||
        resolveWorkflowChildIssueSteps(workflowState).length > 0);
}
function resolveWorkflowChildIssueSteps(workflowState) {
    if (workflowState?.plan === null || workflowState?.plan === undefined) {
        return [];
    }
    return workflowState.plan.steps.filter(types_1.isWorkflowChildIssueStep);
}
function hasLinkedWorkflowChildIssueStep(workflowState) {
    return resolveWorkflowChildIssueSteps(workflowState).some((step) => (0, issue_ref_1.normalizeWorkflowIssueDisplayRef)(step.childIssueRef) !== null);
}
function isRecurringParentState(workflowState) {
    return workflowState?.recurring?.kind === "parent";
}
