//! [`GraphSubscriptionStore`] — Minigraf-backed
//! [`SubscriptionStore`].
//!
//! Same shape as the other graph-backed stores: one
//! `subscription` vertex per subscription, indexed properties
//! (`external_id`, `customer_ref`, `status_code`,
//! `current_period_end`), full state JSON in `state`. No edges
//! yet — subscriptions don't reference the ledger directly; the
//! charge that runs against a due subscription becomes an
//! ordinary `ledger_tx` that joins back via `customer_ref` /
//! external metadata.
use op_subscriptions::{
Error as SubError, Result as SubResult, Subscription, SubscriptionId, SubscriptionStore,
};
use serde_json::Value as Json;
use crate::graph::{GraphHandle, vtypes};
/// Graph-backed subscription store.
pub struct GraphSubscriptionStore {
handle: GraphHandle,
}
impl GraphSubscriptionStore {
/// Construct on a fresh in-memory graph.
#[must_use]
pub fn new_in_memory() -> Self {
Self::with_handle(GraphHandle::new_in_memory())
}
/// Construct on a shared handle.
#[must_use]
pub fn with_handle(handle: GraphHandle) -> Self {
Self { handle }
}
/// Borrow the underlying handle.
#[must_use]
pub fn handle(&self) -> &GraphHandle {
&self.handle
}
/// Diagnostic: number of subscription vertices.
pub fn len(&self) -> usize {
self.handle
.vertices_of_type(vtypes::SUBSCRIPTION)
.map_or(0, |v| v.len())
}
/// True iff no subscriptions stored.
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
fn load(&self, id: SubscriptionId) -> SubResult