use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; #[derive( Debug, Clone, Copy, PartialEq, Eq, Default, EnumIter, DeriveActiveEnum, Serialize, Deserialize, )] #[sea_orm(rs_type = "i16", db_type = "SmallInteger")] pub enum SubscriptionStatus { #[default] Trialing = 0, Active = 1, PastDue = 2, Canceled = 3, Expired = 4, } #[derive( Debug, Clone, Copy, PartialEq, Eq, Default, EnumIter, DeriveActiveEnum, Serialize, Deserialize, )] #[sea_orm(rs_type = "i16", db_type = "SmallInteger")] pub enum BillingInterval { #[default] OneTime = 0, Monthly = 1, Quarterly = 2, Yearly = 3, } use super::payment_orders::PaymentProvider; #[sea_orm::model] #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] #[sea_orm(table_name = "subscription")] pub struct Model { #[sea_orm(primary_key)] pub id: Uuid, #[sea_orm(unique_key = "space_product")] pub space_id: Uuid, #[sea_orm(unique_key = "space_product")] pub product_id: Uuid, pub user_id: Uuid, pub amount: i64, #[sea_orm(default_value = "CNY")] pub currency: String, pub billing_interval: BillingInterval, pub plan: Option, pub status: SubscriptionStatus, pub current_period_start: Option, pub current_period_end: Option, pub cancel_at: Option, pub canceled_at: Option, pub provider: Option, #[sea_orm(unique)] pub provider_subscription_id: Option, pub created_at: OffsetDateTime, #[sea_orm(belongs_to, from = "user_id", to = "uid")] pub user: BelongsTo, #[sea_orm(belongs_to, from = "space_id", to = "id")] pub space: BelongsTo, #[sea_orm(belongs_to, from = "product_id", to = "id")] pub product: BelongsTo, } impl ActiveModelBehavior for ActiveModel {}