/**
 * Builders for constructing ExternalActor objects from GitHub API data.
 *
 * These are used by the issues ingest paths (submitIssue, addIssueMessage,
 * syncIssuesFromGitHub) to populate the request context with external actor
 * provenance before writes.
 */
/**
 * Build an ExternalActor from a GitHub issue's `.user` field.
 * Returns null if the user field is absent (login required; id defaults to 0).
 */
export function buildExternalActorFromGithubIssue(issue, options) {
    const user = issue?.user;
    if (!user?.login)
        return null;
    return {
        provider: "github",
        login: user.login,
        id: user.id ?? 0,
        type: normaliseGithubUserType(user.type),
        verified_via: options?.verified_via ?? "claim",
        event_id: issue?.number,
        ...(options?.repository ? { repository: options.repository } : {}),
    };
}
/**
 * Build an ExternalActor from a GitHub comment's `.user` field.
 * Returns null if the user field is absent (login required; id defaults to 0).
 */
export function buildExternalActorFromGithubComment(comment, issue, options) {
    const user = comment?.user;
    if (!user?.login)
        return null;
    return {
        provider: "github",
        login: user.login,
        id: user.id ?? 0,
        type: normaliseGithubUserType(user.type),
        verified_via: options?.verified_via ?? "claim",
        comment_id: comment?.id,
        event_id: issue?.number,
        ...(options?.repository ? { repository: options.repository } : {}),
    };
}
/**
 * Build an ExternalActor from raw fields (useful for webhook payloads
 * or when the full GitHubIssue/Comment type is not available).
 */
export function buildExternalActor(params) {
    return {
        provider: "github",
        login: params.login,
        id: params.id,
        type: normaliseGithubUserType(params.type),
        verified_via: params.verified_via ?? "claim",
        ...(params.delivery_id ? { delivery_id: params.delivery_id } : {}),
        ...(params.event_type ? { event_type: params.event_type } : {}),
        ...(params.repository ? { repository: params.repository } : {}),
        ...(params.event_id !== undefined ? { event_id: params.event_id } : {}),
        ...(params.comment_id !== undefined ? { comment_id: params.comment_id } : {}),
    };
}
function normaliseGithubUserType(type) {
    if (!type)
        return "User";
    const lower = type.toLowerCase();
    if (lower === "bot")
        return "Bot";
    if (lower === "organization")
        return "Organization";
    return "User";
}
//# sourceMappingURL=external_actor_builder.js.map