use std::collections::HashMap;
use std::future::Future;
use std::pin::Pin;
use super::context::TenantId;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct ResolvedKey {
pub tenant_id: TenantId,
pub allowed_models: Vec<String>,
pub monthly_budget: Option<rust_decimal::Decimal>,
pub currency: Option<String>,
pub metadata: HashMap<String, String>,
pub active: bool,
}
#[derive(Debug, thiserror::Error)]
pub enum KeyResolverError {
#[error("api key not found")]
NotFound,
#[error("api key is inactive")]
Inactive,
#[error("key resolver backend error: {0}")]
Backend(String),
}
pub trait KeyResolver: Send + Sync + 'static {
fn resolve(
&self,
api_key: String,
) -> Pin<Box<dyn Future<Output = Result<ResolvedKey, KeyResolverError>> + Send + 'static>>;
}
#[cfg(test)]
mod tests {
use super::*;
use crate::tenant::InMemoryKeyResolver;
#[allow(dead_code)]
fn _assert_future_is_static_send<T: Future + Send + 'static>(_: T) {}
#[allow(dead_code)]
fn _check_resolve_future_bounds(resolver: &InMemoryKeyResolver) {
_assert_future_is_static_send(resolver.resolve("sk-test".to_owned()));
}
}