"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveLinkedIssuePublishTarget = resolveLinkedIssuePublishTarget;
const pull_request_link_1 = require("../issues/pull-request-link");
const types_1 = require("../platform/ticket-tracker/types");
function resolveLinkedIssuePublishTarget(input) {
    if (input.issue.kind !== types_1.TRACKER_ITEM_KINDS.pullRequest) {
        return {
            kind: "existing_issue",
            issueId: input.issue.id,
            preloadedIssue: input.issue,
        };
    }
    const sourceIssueId = (0, pull_request_link_1.resolveLinkedIssueIdFromPullRequest)({ body: input.issue.body }, input.comments);
    if (sourceIssueId === null) {
        return input.unlinkedPullRequestPolicy === "existing_issue"
            ? {
                kind: "existing_issue",
                issueId: input.issue.id,
                preloadedIssue: input.issue,
            }
            : null;
    }
    return {
        kind: "pull_request_thread",
        pullRequestThreadId: input.issue.id,
        sourceIssueId,
        preloadedIssue: input.issue,
    };
}
