use async_trait::async_trait;
use crate::error::TenancyError;
use crate::resolver::TenantKey;
use crate::tenant::{ConfigValue, Tenant, TenantId};
pub mod cached;
pub mod memory;
#[cfg(feature = "postgres")]
pub mod postgres;
pub use cached::CachedTenantRepository;
pub use memory::MemoryTenantRepository;
#[async_trait]
pub trait TenantRepository: Send + Sync {
async fn all(&self) -> Result<Vec<Tenant>, TenancyError>;
async fn find(&self, id: TenantId) -> Result<Option<Tenant>, TenancyError>;
async fn find_by_key(&self, key: &TenantKey) -> Result<Option<Tenant>, TenancyError>;
async fn create(&self, tenant: &Tenant) -> Result<Tenant, TenancyError>;
async fn update(&self, tenant: &Tenant) -> Result<Tenant, TenancyError>;
async fn delete(&self, id: TenantId) -> Result<bool, TenancyError>;
async fn save_config(
&self,
id: TenantId,
key: &str,
value: &ConfigValue,
) -> Result<(), TenancyError>;
}