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