use chrono::{DateTime, Utc}; use sqlx::{FromRow, Type}; use std::fmt::{Display, Formatter}; #[derive(Debug, Clone, FromRow)] pub struct User { /// Database ID for this uer pub id: u64, /// Nostr pubkey of this user pub pubkey: Vec, /// Timestamp when this user first used the service pub created: DateTime, /// Current balance in milli-sats pub balance: i64, /// When the TOS was accepted pub tos_accepted: Option>, /// Primary stream key pub stream_key: String, /// If the user is an admin pub is_admin: bool, /// If the user is blocked from streaming pub is_blocked: bool, /// Streams are recorded pub recording: bool, /// Default stream title pub title: Option, /// Default stream summary pub summary: Option, /// Default stream image pub image: Option, /// Default tags (comma separated) pub tags: Option, /// Default content warning pub content_warning: Option, /// Default stream goal pub goal: Option, } #[derive(Default, Debug, Clone, PartialEq, Type)] #[repr(u8)] pub enum UserStreamState { #[default] Unknown = 0, Planned = 1, Live = 2, Ended = 3, } impl Display for UserStreamState { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { UserStreamState::Unknown => write!(f, "unknown"), UserStreamState::Planned => write!(f, "planned"), UserStreamState::Live => write!(f, "live"), UserStreamState::Ended => write!(f, "ended"), } } } #[derive(Debug, Clone, Default, FromRow)] pub struct UserStream { pub id: String, pub user_id: u64, pub starts: DateTime, pub ends: Option>, pub state: UserStreamState, pub title: Option, pub summary: Option, pub image: Option, pub thumb: Option, pub tags: Option, pub content_warning: Option, pub goal: Option, pub pinned: Option, pub cost: u64, pub duration: f32, pub fee: Option, pub event: Option, pub endpoint_id: Option, pub last_segment: Option>, } #[derive(Debug, Clone, FromRow)] pub struct UserStreamForward { pub id: u64, pub user_id: u64, pub name: String, pub target: String, } #[derive(Debug, Clone, FromRow)] pub struct UserStreamKey { pub id: u64, pub user_id: u64, pub key: String, pub created: DateTime, pub expires: Option>, pub stream_id: String, } #[derive(Default, Debug, Clone, Type)] #[repr(u8)] pub enum PaymentType { #[default] TopUp = 0, Zap = 1, Credit = 2, Withdrawal = 3, AdmissionFee = 4, } #[derive(Debug, Clone, FromRow)] pub struct Payment { pub payment_hash: Vec, pub user_id: u64, pub invoice: Option, pub is_paid: bool, pub amount: u64, pub created: DateTime, pub nostr: Option, pub payment_type: PaymentType, pub fee: u64, } #[derive(Debug, Clone, FromRow)] pub struct IngestEndpoint { pub id: u64, pub name: String, pub cost: u64, pub capabilities: Option, // JSON array stored as string }