/**
 * RecognitionEvent Database Mapper (spec 097).
 *
 * Maps between RecognitionEvent domain objects and SQLite rows for the
 * `recognition_events` table (migration 102).
 */
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(event) {
    return {
        id: event.id,
        contributor_id: event.contributorId,
        kind: event.kind,
        occurred_at: toMillis(event.occurredAt),
        pr_number: event.prNumber,
        month_recap_id: event.monthRecapId ?? null,
        created_at: toMillis(event.createdAt),
        updated_at: toMillis(event.updatedAt),
    };
}
export function fromDatabase(row) {
    return {
        id: row.id,
        contributorId: row.contributor_id,
        kind: row.kind,
        occurredAt: new Date(row.occurred_at),
        prNumber: row.pr_number,
        monthRecapId: row.month_recap_id ?? undefined,
        createdAt: new Date(row.created_at),
        updatedAt: new Date(row.updated_at),
    };
}
