use super::*;
pub(crate) struct ConfiguredBudgetStore {
pub(crate) store: Arc<dyn BudgetStore>,
pub(crate) hold_capable: bool,
}
pub(crate) fn build_budget_store(
config: &ProtectConfig,
) -> Result<Option<ConfiguredBudgetStore>, ProtectError> {
if let Some(path) = config.budget_db.as_deref() {
let store = chio_store_sqlite::budget_store::SqliteBudgetStore::open(path)
.map_err(|error| ProtectError::Config(error.to_string()))?;
return Ok(Some(ConfiguredBudgetStore {
store: Arc::new(store),
hold_capable: true,
}));
}
if let Some(control_url) = config.control_url.as_deref() {
let token = config.control_token.as_deref().unwrap_or("");
let store =
chio_control_plane::trust_control::service_runtime::budget::build_remote_budget_store(
control_url,
token,
)
.map_err(|error| ProtectError::Config(error.to_string()))?;
return Ok(Some(ConfiguredBudgetStore {
store: Arc::from(store),
hold_capable: false,
}));
}
Ok(None)
}