use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum LicenseTier {
Community,
Professional,
}
impl fmt::Display for LicenseTier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Community => write!(f, "Community"),
Self::Professional => write!(f, "Professional"),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct License {
pub id: String,
pub customer_name: String,
pub slots_count: u32,
pub expiration_date: String,
pub features: Vec<String>,
pub tier: LicenseTier,
}
impl License {
pub fn is_valid(&self) -> bool {
match chrono::DateTime::parse_from_rfc3339(&self.expiration_date) {
Ok(expiration) => chrono::Utc::now() <= expiration.with_timezone(&chrono::Utc),
Err(_) => false,
}
}
pub fn has_capacity(&self, current_slots: u32) -> bool {
current_slots < self.slots_count
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SignedLicense {
pub payload: String,
pub signature: String,
}