use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::domain::{Job, JobKind, JobStatus};
use crate::ids::JobId;
#[derive(Debug, Clone, Deserialize, utoipa::ToSchema)]
pub struct CreateJobRequest {
pub kind: JobKind,
#[schema(value_type = Object)]
pub payload: serde_json::Value,
#[serde(default)]
pub max_attempts: Option<i32>,
#[serde(default)]
pub idempotency_key: Option<String>,
}
#[derive(Debug, Clone, Serialize, utoipa::ToSchema)]
pub struct JobResponse {
pub id: JobId,
pub kind: JobKind,
pub status: JobStatus,
pub attempts: i32,
pub max_attempts: i32,
pub last_error: Option<String>,
#[schema(value_type = Object)]
pub payload: serde_json::Value,
pub run_at: DateTime<Utc>,
pub idempotency_key: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl From<Job> for JobResponse {
fn from(j: Job) -> Self {
Self {
id: j.id,
kind: j.kind,
status: j.status,
attempts: j.attempts,
max_attempts: j.max_attempts,
last_error: j.last_error,
payload: j.payload,
run_at: j.run_at,
idempotency_key: j.idempotency_key,
created_at: j.created_at,
updated_at: j.updated_at,
}
}
}
#[derive(Debug, Clone, Deserialize, utoipa::IntoParams)]
pub struct ListJobsQuery {
pub status: Option<JobStatus>,
pub kind: Option<JobKind>,
pub limit: Option<i64>,
pub offset: Option<i64>,
}
#[derive(Debug, Clone, Serialize, utoipa::ToSchema)]
pub struct CancelResponse {
pub status: &'static str,
pub job_id: JobId,
}
#[derive(Debug, Clone, Serialize, utoipa::ToSchema)]
pub struct HealthResponse {
pub status: &'static str,
}
#[derive(Debug, Clone, Serialize, utoipa::ToSchema)]
pub struct ErrorBody {
pub error: &'static str,
pub message: String,
}