use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use super::UseCase;
use crate::domain::entity::UserQuota;
use crate::infrastructure::persistence::UserQuotaRepository;
#[derive(Debug, Clone)]
pub struct CreateUserQuotaInput {
pub user_id: Uuid,
pub limit_bytes: i64,
pub used_bytes: i64,
pub file_count: i32,
pub max_file_size: Option<i64>,
pub max_file_count: Option<i32>,
pub tier: String,
pub warning_threshold_percent: i32,
pub last_warning_sent_at: Option<DateTime<Utc>>,
pub peak_usage_bytes: i64,
pub peak_usage_at: Option<DateTime<Utc>>,
pub metadata: serde_json::Value,
}
#[derive(Debug, Clone)]
pub struct CreateUserQuotaOutput {
pub user_quota: UserQuota,
}
pub struct CreateUserQuotaUseCase {
repository: Arc<UserQuotaRepository>,
}
impl CreateUserQuotaUseCase {
pub fn new(repository: Arc<UserQuotaRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for CreateUserQuotaUseCase {
type Input = CreateUserQuotaInput;
type Output = CreateUserQuotaOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = UserQuota {
id: None,
user_id: input.user_id,
limit_bytes: input.limit_bytes,
used_bytes: input.used_bytes,
file_count: input.file_count,
max_file_size: input.max_file_size,
max_file_count: input.max_file_count,
tier: input.tier,
warning_threshold_percent: input.warning_threshold_percent,
last_warning_sent_at: input.last_warning_sent_at,
peak_usage_bytes: input.peak_usage_bytes,
peak_usage_at: input.peak_usage_at,
metadata: input.metadata,
};
let created = self.repository.create(entity).await?;
Ok(CreateUserQuotaOutput { user_quota: created })
}
}