64 lines
2.5 KiB
Rust
64 lines
2.5 KiB
Rust
use crate::DateTimeUtc;
|
|
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Subscription record — tracks paid plans for users or projects.
|
|
/// Each subscription defines quota limits (6h, weekly, monthly) and payment metadata.
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
|
#[sea_orm(table_name = "subscription")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key)]
|
|
pub id: Uuid,
|
|
/// Who is subscribed: "user" or "project"
|
|
pub scope: String,
|
|
/// The UUID of the user or project
|
|
#[sea_orm(column_name = "scope_id")]
|
|
pub scope_id: Uuid,
|
|
/// Subscription start time
|
|
pub start_at: DateTimeUtc,
|
|
/// Subscription end (expiry) time
|
|
pub end_at: DateTimeUtc,
|
|
/// External order / transaction ID from payment platform
|
|
#[sea_orm(column_type = "Text", nullable)]
|
|
pub order_id: Option<String>,
|
|
/// Payment platform identifier (e.g. "stripe", "alipay", "wechat")
|
|
pub platform: String,
|
|
/// Human-readable plan name (e.g. "Pro Monthly", "Team Annual")
|
|
#[sea_orm(column_type = "Text", nullable)]
|
|
pub plan_name: Option<String>,
|
|
/// 6-hour quota limit (auto-reset every 6 hours)
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub quota_6h: Decimal,
|
|
/// 6-hour quota used so far in current window
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub quota_6h_used: Decimal,
|
|
/// Next 6-hour reset timestamp
|
|
pub quota_6h_reset_at: Option<DateTimeUtc>,
|
|
/// Weekly quota limit
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub quota_weekly: Decimal,
|
|
/// Weekly quota used so far
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub quota_weekly_used: Decimal,
|
|
/// Next weekly reset timestamp
|
|
pub quota_weekly_reset_at: Option<DateTimeUtc>,
|
|
/// Monthly quota limit
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub quota_monthly: Decimal,
|
|
/// Monthly quota used so far
|
|
#[sea_orm(column_type = "Decimal(Some((20, 4)))", default_value = 0)]
|
|
pub quota_monthly_used: Decimal,
|
|
/// Whether subscription is currently active
|
|
#[sea_orm(default_value = false)]
|
|
pub is_active: bool,
|
|
#[sea_orm(column_type = "Text")]
|
|
pub currency: String,
|
|
pub updated_at: DateTimeUtc,
|
|
pub created_at: DateTimeUtc,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|