Skip to main content

max / makenotwork

2.7 KB · 74 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::*;
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 pub code: String,
54 pub code_purpose: super::super::CodePurpose,
55 pub discount_type: Option<super::super::DiscountType>,
56 pub discount_value: Option<i32>,
57 pub min_price_cents: i32,
58 pub trial_days: Option<i32>,
59 pub item_id: Option<ItemId>,
60 pub project_id: Option<ProjectId>,
61 pub tier_id: Option<SubscriptionTierId>,
62 pub max_uses: Option<i32>,
63 pub use_count: i32,
64 pub expires_at: Option<DateTime<Utc>>,
65 pub starts_at: Option<DateTime<Utc>>,
66 pub created_at: DateTime<Utc>,
67 /// Whether this code is platform-wide (Fan+ credits).
68 pub is_platform_wide: bool,
69 /// Joined item title, if item-scoped.
70 pub item_title: Option<String>,
71 /// Joined project title, if project-scoped.
72 pub project_title: Option<String>,
73 }
74