"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.canPendingPlanningBypassOpenExecutionBlockers = canPendingPlanningBypassOpenExecutionBlockers;
const preflight_resolution_marker_1 = require("./preflight-resolution-marker");
async function canPendingPlanningBypassOpenExecutionBlockers(input) {
    if (!input.hasPendingPlanning) {
        return false;
    }
    if (input.openExecutionBlockers.length === 0) {
        return true;
    }
    return !(await hasOpenPreflightResolutionBlocker({
        parentIssueId: input.parentIssueId,
        openExecutionBlockers: input.openExecutionBlockers,
        ticketTracker: input.ticketTracker,
    }));
}
async function hasOpenPreflightResolutionBlocker(input) {
    const blockerIssueIds = [
        ...new Set(input.openExecutionBlockers.map((blocker) => blocker.id)),
    ];
    for (const blockerIssueId of blockerIssueIds) {
        const blockerIssue = await input.ticketTracker.getIssueRecord(blockerIssueId);
        if ((0, preflight_resolution_marker_1.isPreflightResolutionForParentIssue)({
            issue: blockerIssue,
            parentIssueId: input.parentIssueId,
        })) {
            return true;
        }
    }
    return false;
}
