#![forbid(unsafe_code)]
#![warn(missing_docs, missing_debug_implementations)]
mod error;
mod types;
use std::fmt::Debug;
use async_trait::async_trait;
pub use error::StorageError;
use secrecy::SecretString;
pub use types::{
AvailableChannelInfo, AvailableModelInfo, Channel, CompressionSavingsReport, CostAggregate,
CostFilter, CostGroupBy, CostRecord, Model, ModelMapping, ProtocolEntry, Provider,
SeedEntryStatus, SeedManifest, SeedManifestEntry, SeedStatus, SubscriptionFee, SwitchLog,
TimeRange,
};
#[async_trait]
pub trait Storage: Send + Sync + Debug {
async fn list_providers(&self) -> Result<Vec<Provider>, StorageError>;
async fn get_provider(&self, id: &str) -> Result<Option<Provider>, StorageError>;
async fn list_models(&self, provider_id: Option<&str>) -> Result<Vec<Model>, StorageError>;
async fn get_model(&self, id: &str) -> Result<Option<Model>, StorageError>;
async fn list_channels(&self, model_id: Option<&str>) -> Result<Vec<Channel>, StorageError>;
async fn get_channel(&self, id: &str) -> Result<Option<Channel>, StorageError>;
async fn upsert_channel(&self, channel: &Channel) -> Result<(), StorageError>;
async fn set_channel_enabled(&self, id: &str, enabled: bool) -> Result<(), StorageError>;
async fn set_channel_api_key(&self, id: &str, key: &SecretString) -> Result<(), StorageError>;
#[allow(clippy::too_many_arguments)]
async fn update_channel(
&self,
id: &str,
name: Option<&str>,
enabled: Option<bool>,
priority: Option<u32>,
monthly_quota: Option<u64>,
quota_policy: Option<&str>,
protocols: Option<&str>,
force_protocol: Option<&str>,
) -> Result<Channel, StorageError>;
async fn delete_channel(&self, id: &str) -> Result<(), StorageError>;
async fn mark_channel_healthy(&self, id: &str) -> Result<(), StorageError>;
async fn record_channel_failure(&self, id: &str) -> Result<(), StorageError>;
async fn list_mappings(&self, channel_id: &str) -> Result<Vec<ModelMapping>, StorageError>;
async fn upsert_mapping(&self, mapping: &ModelMapping) -> Result<(), StorageError>;
async fn set_mapping_enabled(&self, id: &str, enabled: bool) -> Result<(), StorageError>;
async fn delete_mapping(&self, id: &str) -> Result<(), StorageError>;
async fn list_all_mappings(&self) -> Result<Vec<ModelMapping>, StorageError>;
async fn insert_cost_record(&self, record: &CostRecord) -> Result<(), StorageError>;
async fn query_cost_records(&self, filter: CostFilter)
-> Result<Vec<CostRecord>, StorageError>;
async fn aggregate_costs(
&self,
group_by: CostGroupBy,
range: TimeRange,
) -> Result<Vec<CostAggregate>, StorageError>;
async fn prune_cost_records(&self, older_than_days: u32) -> Result<u64, StorageError>;
async fn list_projects(&self) -> Result<Vec<String>, StorageError>;
async fn insert_switch_log(&self, log: &SwitchLog) -> Result<(), StorageError>;
async fn query_switch_logs(&self, limit: Option<u32>) -> Result<Vec<SwitchLog>, StorageError>;
async fn list_available_channels(&self) -> Result<Vec<AvailableChannelInfo>, StorageError>;
async fn insert_subscription_fee(&self, fee: &SubscriptionFee) -> Result<(), StorageError>;
async fn query_subscription_fees(
&self,
channel: Option<&str>,
month: Option<&str>,
) -> Result<Vec<SubscriptionFee>, StorageError>;
async fn migrate(&self) -> Result<(), StorageError>;
async fn health_check(&self) -> Result<bool, StorageError>;
fn max_connections(&self) -> usize;
}
#[async_trait]
pub trait SeedManager: Send + Sync {
async fn seed_init(&self) -> Result<SeedStatus, StorageError>;
async fn seed_refresh(&self, url: Option<&str>) -> Result<SeedStatus, StorageError>;
async fn seed_status(&self) -> Result<SeedStatus, StorageError>;
async fn seed_check_remote(&self, url: Option<&str>) -> Result<SeedStatus, StorageError>;
}