e034b46
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<String>,
pub status: SubscriptionStatus,
pub current_period_start: Option<OffsetDateTime>,
pub current_period_end: Option<OffsetDateTime>,
pub cancel_at: Option<OffsetDateTime>,
pub canceled_at: Option<OffsetDateTime>,
pub provider: Option<PaymentProvider>,
#[sea_orm(unique)]
pub provider_subscription_id: Option<String>,
pub created_at: OffsetDateTime,
#[sea_orm(belongs_to, from = "user_id", to = "uid")]
pub user: BelongsTo<super::super::user::users::Entity>,
#[sea_orm(belongs_to, from = "space_id", to = "id")]
pub space: BelongsTo<super::super::space::spaces::Entity>,
#[sea_orm(belongs_to, from = "product_id", to = "id")]
pub product: BelongsTo<super::super::products::products::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}