use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use super::UseCase;
use crate::domain::entity::ProcessingJob;
use crate::infrastructure::persistence::ProcessingJobRepository;
#[derive(Debug, Clone)]
pub struct CreateProcessingJobInput {
pub file_id: Uuid,
pub job_type: ProcessingJobType,
pub status: JobStatus,
pub priority: i32,
pub input_data: Option<serde_json::Value>,
pub result_data: Option<serde_json::Value>,
pub error_message: Option<String>,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
pub retry_count: i32,
pub max_retries: i32,
pub metadata: Option<serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct CreateProcessingJobOutput {
pub processing_job: ProcessingJob,
}
pub struct CreateProcessingJobUseCase {
repository: Arc<ProcessingJobRepository>,
}
impl CreateProcessingJobUseCase {
pub fn new(repository: Arc<ProcessingJobRepository>) -> Self {
Self { repository }
}
}
#[async_trait]
impl UseCase for CreateProcessingJobUseCase {
type Input = CreateProcessingJobInput;
type Output = CreateProcessingJobOutput;
async fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let entity = ProcessingJob {
id: None,
file_id: input.file_id,
job_type: input.job_type,
status: input.status,
priority: input.priority,
input_data: input.input_data,
result_data: input.result_data,
error_message: input.error_message,
started_at: input.started_at,
completed_at: input.completed_at,
retry_count: input.retry_count,
max_retries: input.max_retries,
metadata: input.metadata,
};
let created = self.repository.create(entity).await?;
Ok(CreateProcessingJobOutput { processing_job: created })
}
}