use std::sync::Arc;
use anyhow::{Result, anyhow};
use async_trait::async_trait;
use uuid::Uuid;
use super::UseCase;
use crate::infrastructure::persistence::FileVersionRepository;
#[derive(Debug, Clone)]
pub struct DeleteFileVersionInput {
pub id: Uuid,
pub hard_delete: bool,
}
#[derive(Debug, Clone)]
pub struct DeleteFileVersionOutput {
pub deleted: bool,
}
pub struct DeleteFileVersionUseCase {
repository: Arc<FileVersionRepository>,
}
impl DeleteFileVersionUseCase {
pub fn new(repository: Arc<FileVersionRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for DeleteFileVersionUseCase {
type Input = DeleteFileVersionInput;
type Output = DeleteFileVersionOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let _ = self.repository.find_by_id(input.id).await?
.ok_or_else(|| anyhow!("FileVersion not found"))?;
if input.hard_delete {
self.repository.delete(input.id).await?;
} else {
self.repository.soft_delete(input.id).await?;
}
Ok(DeleteFileVersionOutput { deleted: true })
}
}