Skip to main content

max / makenotwork

3.0 KB · 77 lines History Blame Raw
1 //! Promo code models.
2
3 use chrono::{DateTime, Utc};
4 use serde::Serialize;
5 use sqlx::FromRow;
6
7 use super::super::id_types::{ItemId, ProjectId, PromoCodeId, SubscriptionTierId, UserId};
8
9 /// A unified promo code (discount, free access, or free trial).
10 #[derive(Debug, Clone, FromRow, Serialize)]
11 pub struct DbPromoCode {
12 /// Database primary key.
13 pub id: PromoCodeId,
14 /// Creator who owns this code.
15 pub creator_id: UserId,
16 /// The code string entered by buyers.
17 pub code: String,
18 /// What this code does: discount, free_access, or free_trial.
19 pub code_purpose: super::super::CodePurpose,
20 /// Discount type (percentage or fixed). Present when purpose = discount.
21 pub discount_type: Option<super::super::DiscountType>,
22 /// Discount amount: percentage value or cents. Present when purpose = discount.
23 pub discount_value: Option<i32>,
24 /// Minimum item price (cents) for discount codes to apply.
25 pub min_price_cents: i32,
26 /// Number of free trial days. Present when purpose = free_trial.
27 pub trial_days: Option<i32>,
28 /// Restrict to a specific item.
29 pub item_id: Option<ItemId>,
30 /// Restrict to a specific project.
31 pub project_id: Option<ProjectId>,
32 /// Restrict to a specific subscription tier.
33 pub tier_id: Option<SubscriptionTierId>,
34 /// Maximum number of uses (NULL = unlimited).
35 pub max_uses: Option<i32>,
36 /// Current number of times this code has been used.
37 pub use_count: i32,
38 /// When this code expires (NULL = never).
39 pub expires_at: Option<DateTime<Utc>>,
40 /// When this code becomes active (NULL = immediately).
41 pub starts_at: Option<DateTime<Utc>>,
42 /// When this code was created.
43 pub created_at: DateTime<Utc>,
44 /// Whether this code is platform-wide (Fan+ credits, usable on any creator's items).
45 pub is_platform_wide: bool,
46 }
47
48 /// Promo code with joined item/project names for dashboard display.
49 #[derive(Debug, Clone, FromRow)]
50 pub struct DbPromoCodeWithNames {
51 pub id: PromoCodeId,
52 pub creator_id: UserId,
53 /// The issuing creator's settlement currency, so a fixed-amount discount
54 /// renders in the money it will actually come off.
55 pub settlement_currency: crate::currency::SettlementCurrency,
56 pub code: String,
57 pub code_purpose: super::super::CodePurpose,
58 pub discount_type: Option<super::super::DiscountType>,
59 pub discount_value: Option<i32>,
60 pub min_price_cents: i32,
61 pub trial_days: Option<i32>,
62 pub item_id: Option<ItemId>,
63 pub project_id: Option<ProjectId>,
64 pub tier_id: Option<SubscriptionTierId>,
65 pub max_uses: Option<i32>,
66 pub use_count: i32,
67 pub expires_at: Option<DateTime<Utc>>,
68 pub starts_at: Option<DateTime<Utc>>,
69 pub created_at: DateTime<Utc>,
70 /// Whether this code is platform-wide (Fan+ credits).
71 pub is_platform_wide: bool,
72 /// Joined item title, if item-scoped.
73 pub item_title: Option<String>,
74 /// Joined project title, if project-scoped.
75 pub project_title: Option<String>,
76 }
77