public enum DigitizationEventType
{
    Uploaded,
    EntryStarted,
    SubmittedForVerification,
    Rejected,
    Verified,
    VerifiedPendingClinical,
    AwaitingClinicalApproval,
    Approved,
    Promoted,
    LiveCaptureAttested,
    CorrectionRequested,
    VerificationFailed,
    Superseded,
    CorrectionPromoted,
    CorrectionUploaded,
    PromotionRetrySucceeded,
    PromotionRetryFailed,
    PromotionRetryExhausted,
    PromotionFailed,
    DocumentAccessed,
    Cancelled,
    DraftFieldUpdated,
    DraftObservationDeleted,
    OcrStarted,
    OcrCompleted,
    OcrFailed
}

public static class DigitizationEventTypeExtensions
{
    public static string ToDbString(this DigitizationEventType t) => t switch
    {
        DigitizationEventType.Uploaded                  => "uploaded",
        DigitizationEventType.EntryStarted              => "entry_started",
        DigitizationEventType.SubmittedForVerification  => "submitted_for_verification",
        DigitizationEventType.Rejected                  => "rejected",
        DigitizationEventType.Verified                  => "verified",
        DigitizationEventType.VerifiedPendingClinical   => "verified_pending_clinical",
        DigitizationEventType.AwaitingClinicalApproval  => "awaiting_clinical_approval",
        DigitizationEventType.Approved                  => "approved",
        DigitizationEventType.Promoted                  => "promoted",
        DigitizationEventType.LiveCaptureAttested       => "live_capture_attested",
        DigitizationEventType.CorrectionRequested       => "correction_requested",
        DigitizationEventType.VerificationFailed        => "verification_failed",
        DigitizationEventType.Superseded                => "superseded",
        DigitizationEventType.CorrectionPromoted        => "correction_promoted",
        DigitizationEventType.CorrectionUploaded        => "correction_uploaded",
        DigitizationEventType.PromotionRetrySucceeded     => "promotion_retry_succeeded",
        DigitizationEventType.PromotionRetryFailed        => "promotion_retry_failed",
        DigitizationEventType.PromotionRetryExhausted     => "promotion_retry_exhausted",
        DigitizationEventType.PromotionFailed             => "promotion_failed",
        DigitizationEventType.DocumentAccessed            => "document_accessed",
        DigitizationEventType.Cancelled                   => "cancelled",
        DigitizationEventType.DraftFieldUpdated            => "draft_field_updated",
        DigitizationEventType.DraftObservationDeleted      => "draft_observation_deleted",
        DigitizationEventType.OcrStarted                   => "ocr_started",
        DigitizationEventType.OcrCompleted                 => "ocr_completed",
        DigitizationEventType.OcrFailed                    => "ocr_failed",
        _ => throw new ArgumentOutOfRangeException(nameof(t))
    };

    public static DigitizationEventType FromDbString(string v) => v switch
    {
        "uploaded"                   => DigitizationEventType.Uploaded,
        "entry_started"              => DigitizationEventType.EntryStarted,
        "submitted_for_verification" => DigitizationEventType.SubmittedForVerification,
        "rejected"                   => DigitizationEventType.Rejected,
        "verified"                   => DigitizationEventType.Verified,
        "verified_pending_clinical"  => DigitizationEventType.VerifiedPendingClinical,
        "awaiting_clinical_approval" => DigitizationEventType.AwaitingClinicalApproval,
        "approved"                   => DigitizationEventType.Approved,
        "promoted"                   => DigitizationEventType.Promoted,
        "live_capture_attested"      => DigitizationEventType.LiveCaptureAttested,
        "correction_requested"       => DigitizationEventType.CorrectionRequested,
        "verification_failed"        => DigitizationEventType.VerificationFailed,
        "superseded"                 => DigitizationEventType.Superseded,
        "correction_promoted"        => DigitizationEventType.CorrectionPromoted,
        "correction_uploaded"        => DigitizationEventType.CorrectionUploaded,
        "promotion_retry_succeeded"  => DigitizationEventType.PromotionRetrySucceeded,
        "promotion_retry_failed"     => DigitizationEventType.PromotionRetryFailed,
        "promotion_retry_exhausted"  => DigitizationEventType.PromotionRetryExhausted,
        "promotion_failed"           => DigitizationEventType.PromotionFailed,
        "document_accessed"          => DigitizationEventType.DocumentAccessed,
        "cancelled"                  => DigitizationEventType.Cancelled,
        "draft_field_updated"        => DigitizationEventType.DraftFieldUpdated,
        "draft_observation_deleted"  => DigitizationEventType.DraftObservationDeleted,
        "ocr_started"                => DigitizationEventType.OcrStarted,
        "ocr_completed"              => DigitizationEventType.OcrCompleted,
        "ocr_failed"                 => DigitizationEventType.OcrFailed,
        _ => throw new ArgumentOutOfRangeException(nameof(v), $"Unknown digitization event type: '{v}'")
    };
}