use async_trait::async_trait;
use modkit_db::secure::DbTx;
use modkit_security::AccessScope;
use uuid::Uuid;
use crate::domain::error::DomainError;
use crate::domain::model::quota::{SettlementInput, SettlementOutcome};
use crate::domain::repos::QuotaUsageRepository;
use crate::domain::service::QuotaService;
use crate::domain::stream_events::QuotaWarning;
#[async_trait]
pub trait QuotaSettler: Send + Sync {
async fn settle_in_tx(
&self,
tx: &DbTx<'_>,
scope: &AccessScope,
input: SettlementInput,
) -> Result<SettlementOutcome, DomainError>;
}
#[async_trait]
impl<QR: QuotaUsageRepository + 'static> QuotaSettler for QuotaService<QR> {
async fn settle_in_tx(
&self,
tx: &DbTx<'_>,
scope: &AccessScope,
input: SettlementInput,
) -> Result<SettlementOutcome, DomainError> {
self.settle(tx, scope, input).await
}
}
#[async_trait]
pub trait QuotaWarningsProvider: Send + Sync {
async fn get_quota_warnings(
&self,
scope: &AccessScope,
tenant_id: Uuid,
user_id: Uuid,
) -> Result<Vec<QuotaWarning>, DomainError>;
}
#[async_trait]
impl<QR: QuotaUsageRepository + 'static> QuotaWarningsProvider for QuotaService<QR> {
async fn get_quota_warnings(
&self,
scope: &AccessScope,
tenant_id: Uuid,
user_id: Uuid,
) -> Result<Vec<QuotaWarning>, DomainError> {
self.compute_quota_warnings(scope, tenant_id, user_id).await
}
}