export function buildCheckoutStatusPayloadFromSnapshot({ cwd, requestId, snapshot, }) {
    if (!snapshot.git.isGit) {
        return {
            cwd,
            isGit: false,
            repoRoot: null,
            currentBranch: null,
            isDirty: null,
            baseRef: null,
            aheadBehind: null,
            aheadOfOrigin: null,
            behindOfOrigin: null,
            hasRemote: false,
            remoteUrl: null,
            isPaseoOwnedWorktree: false,
            error: null,
            requestId,
        };
    }
    if (snapshot.git.repoRoot === null || snapshot.git.isDirty === null) {
        throw new Error("Workspace git snapshot is missing required checkout status fields");
    }
    if (snapshot.git.isPaseoOwnedWorktree) {
        if (snapshot.git.mainRepoRoot === null || snapshot.git.baseRef === null) {
            throw new Error("Workspace git snapshot is missing required worktree status fields");
        }
        return {
            cwd,
            isGit: true,
            repoRoot: snapshot.git.repoRoot,
            mainRepoRoot: snapshot.git.mainRepoRoot,
            currentBranch: snapshot.git.currentBranch ?? null,
            isDirty: snapshot.git.isDirty,
            baseRef: snapshot.git.baseRef,
            aheadBehind: snapshot.git.aheadBehind ?? null,
            aheadOfOrigin: snapshot.git.aheadOfOrigin ?? null,
            behindOfOrigin: snapshot.git.behindOfOrigin ?? null,
            hasRemote: snapshot.git.hasRemote,
            remoteUrl: snapshot.git.remoteUrl,
            isPaseoOwnedWorktree: true,
            error: null,
            requestId,
        };
    }
    return {
        cwd,
        isGit: true,
        repoRoot: snapshot.git.repoRoot,
        mainRepoRoot: snapshot.git.mainRepoRoot,
        currentBranch: snapshot.git.currentBranch ?? null,
        isDirty: snapshot.git.isDirty,
        baseRef: snapshot.git.baseRef ?? null,
        aheadBehind: snapshot.git.aheadBehind ?? null,
        aheadOfOrigin: snapshot.git.aheadOfOrigin ?? null,
        behindOfOrigin: snapshot.git.behindOfOrigin ?? null,
        hasRemote: snapshot.git.hasRemote,
        remoteUrl: snapshot.git.remoteUrl,
        isPaseoOwnedWorktree: false,
        error: null,
        requestId,
    };
}
export function buildCheckoutPrStatusPayloadFromSnapshot({ cwd, requestId, snapshot, }) {
    return {
        cwd,
        status: normalizeCheckoutPrStatusPayload(snapshot.github.pullRequest),
        githubFeaturesEnabled: snapshot.github.featuresEnabled,
        error: snapshot.github.error
            ? {
                code: "UNKNOWN",
                message: snapshot.github.error.message,
            }
            : null,
        requestId,
    };
}
export function normalizeCheckoutPrStatusPayload(status) {
    if (!status) {
        return null;
    }
    const payload = {
        number: status.number,
        url: status.url,
        title: status.title,
        state: status.state,
        repoOwner: status.repoOwner,
        repoName: status.repoName,
        baseRefName: status.baseRefName,
        headRefName: status.headRefName,
        isMerged: status.isMerged,
        isDraft: status.isDraft ?? false,
        mergeable: status.mergeable ?? "UNKNOWN",
        checks: status.checks ?? [],
        checksStatus: status.checksStatus,
        reviewDecision: status.reviewDecision,
    };
    if (status.github) {
        payload.github = status.github;
    }
    return payload;
}
//# sourceMappingURL=status-projection.js.map