use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use super::UseCase;
use crate::domain::entity::ContentHash;
use crate::infrastructure::persistence::ContentHashRepository;
#[derive(Debug, Clone)]
pub struct CreateContentHashInput {
pub hash: String,
pub size_bytes: i64,
pub storage_key: String,
pub storage_backend: StorageBackend,
pub reference_count: i32,
pub first_uploaded_at: DateTime<Utc>,
pub last_referenced_at: DateTime<Utc>,
pub fingerprint: Option<String>,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct CreateContentHashOutput {
pub content_hash: ContentHash,
}
pub struct CreateContentHashUseCase {
repository: Arc<ContentHashRepository>,
}
impl CreateContentHashUseCase {
pub fn new(repository: Arc<ContentHashRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for CreateContentHashUseCase {
type Input = CreateContentHashInput;
type Output = CreateContentHashOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = ContentHash {
id: None,
hash: input.hash,
size_bytes: input.size_bytes,
storage_key: input.storage_key,
storage_backend: input.storage_backend,
reference_count: input.reference_count,
first_uploaded_at: input.first_uploaded_at,
last_referenced_at: input.last_referenced_at,
fingerprint: input.fingerprint,
metadata: input.metadata,
};
let created = self.repository.create(entity).await?;
Ok(CreateContentHashOutput { content_hash: created })
}
}