//! Promo code models. use chrono::{DateTime, Utc}; use serde::Serialize; use sqlx::FromRow; use super::super::id_types::*; /// A unified promo code (discount, free access, or free trial). #[derive(Debug, Clone, FromRow, Serialize)] pub struct DbPromoCode { /// Database primary key. pub id: PromoCodeId, /// Creator who owns this code. pub creator_id: UserId, /// The code string entered by buyers. pub code: String, /// What this code does: discount, free_access, or free_trial. pub code_purpose: super::super::CodePurpose, /// Discount type (percentage or fixed). Present when purpose = discount. pub discount_type: Option, /// Discount amount: percentage value or cents. Present when purpose = discount. pub discount_value: Option, /// Minimum item price (cents) for discount codes to apply. pub min_price_cents: i32, /// Number of free trial days. Present when purpose = free_trial. pub trial_days: Option, /// Restrict to a specific item. pub item_id: Option, /// Restrict to a specific project. pub project_id: Option, /// Restrict to a specific subscription tier. pub tier_id: Option, /// Maximum number of uses (NULL = unlimited). pub max_uses: Option, /// Current number of times this code has been used. pub use_count: i32, /// When this code expires (NULL = never). pub expires_at: Option>, /// When this code becomes active (NULL = immediately). pub starts_at: Option>, /// When this code was created. pub created_at: DateTime, /// Whether this code is platform-wide (Fan+ credits, usable on any creator's items). pub is_platform_wide: bool, } /// Promo code with joined item/project names for dashboard display. #[derive(Debug, Clone, FromRow)] pub struct DbPromoCodeWithNames { pub id: PromoCodeId, pub creator_id: UserId, pub code: String, pub code_purpose: super::super::CodePurpose, pub discount_type: Option, pub discount_value: Option, pub min_price_cents: i32, pub trial_days: Option, pub item_id: Option, pub project_id: Option, pub tier_id: Option, pub max_uses: Option, pub use_count: i32, pub expires_at: Option>, pub starts_at: Option>, pub created_at: DateTime, /// Whether this code is platform-wide (Fan+ credits). pub is_platform_wide: bool, /// Joined item title, if item-scoped. pub item_title: Option, /// Joined project title, if project-scoped. pub project_title: Option, }