/**
 * Contributor Database Mapper (spec 097).
 *
 * Maps between Contributor domain objects and SQLite rows for the
 * `contributors` table (migration 101).
 */
function toMillis(value) {
    if (value instanceof Date)
        return value.getTime();
    if (typeof value === 'number')
        return value;
    if (typeof value === 'string')
        return new Date(value).getTime();
    return 0;
}
export function toDatabase(contributor) {
    return {
        id: contributor.id,
        github_login: contributor.githubLogin,
        display_name: contributor.displayName ?? null,
        avatar_url: contributor.avatarUrl ?? null,
        lane: contributor.lane ?? null,
        level: contributor.level,
        first_contribution_at: toMillis(contributor.firstContributionAt),
        last_contribution_at: toMillis(contributor.lastContributionAt),
        pr_count: contributor.prCount,
        issue_count: contributor.issueCount,
        created_at: toMillis(contributor.createdAt),
        updated_at: toMillis(contributor.updatedAt),
    };
}
export function fromDatabase(row) {
    return {
        id: row.id,
        githubLogin: row.github_login,
        displayName: row.display_name ?? undefined,
        avatarUrl: row.avatar_url ?? undefined,
        lane: (row.lane ?? undefined),
        level: row.level,
        firstContributionAt: new Date(row.first_contribution_at),
        lastContributionAt: new Date(row.last_contribution_at),
        prCount: row.pr_count,
        issueCount: row.issue_count,
        createdAt: new Date(row.created_at),
        updatedAt: new Date(row.updated_at),
    };
}
