use serde::{Deserialize, Serialize};
use super::{
entitlement::Entitlement, entitlement_product_ref::EntitlementProductRef,
feature_id::FeatureId, feature_status::FeatureStatus, feature_type::FeatureType,
};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Feature {
pub code: String,
pub created_at: chrono::DateTime<chrono::Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entitlement: Option<Entitlement>,
pub feature_type: FeatureType,
pub id: FeatureId,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub product: Option<EntitlementProductRef>,
pub status: FeatureStatus,
#[serde(flatten)]
pub extra: serde_json::Map<String, serde_json::Value>,
}
impl Feature {
#[must_use]
pub fn new(
code: impl Into<String>,
created_at: chrono::DateTime<chrono::Utc>,
feature_type: FeatureType,
id: impl Into<FeatureId>,
name: impl Into<String>,
status: FeatureStatus,
) -> Self {
Self {
code: code.into(),
created_at,
description: None,
entitlement: None,
feature_type,
id: id.into(),
name: name.into(),
product: None,
status,
extra: serde_json::Map::new(),
}
}
}