1use chrono::{DateTime, Utc};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use std::collections::HashMap;
6use url::Url;
7
8#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
9#[serde(rename_all = "lowercase")]
10pub enum Status {
11 #[serde(skip)]
12 Idle,
13
14 Failed,
15 Starting,
16 Canceled,
17 Succeeded,
18 Processing,
19}
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, JsonSchema)]
22pub enum WebhookEvent {
23 Start,
24 Output,
25 Logs,
26 Completed,
27}
28
29#[derive(Debug, Clone, serde::Deserialize, JsonSchema)]
30pub struct Request<T = Value> {
31 pub webhook: Option<Url>,
32 pub webhook_event_filters: Option<Vec<WebhookEvent>>,
33
34 pub input: T,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
38pub struct Response<Req = Value, Res = Value> {
39 pub input: Option<Req>,
40 pub output: Option<Res>,
41
42 pub id: Option<String>,
43 pub version: Option<String>,
44
45 pub created_at: Option<DateTime<Utc>>,
46 pub started_at: Option<DateTime<Utc>>,
47 pub completed_at: Option<DateTime<Utc>>,
48
49 pub logs: String,
50 pub status: Status,
51 pub error: Option<String>,
52
53 pub metrics: Option<HashMap<String, Value>>,
54}
55
56impl Default for Response {
57 fn default() -> Self {
58 Self {
59 id: None,
60 error: None,
61 input: None,
62 output: None,
63 metrics: None,
64 version: None,
65 created_at: None,
66 logs: String::new(),
67 status: Status::Starting,
68 started_at: Utc::now().into(),
69 completed_at: Utc::now().into(),
70 }
71 }
72}
73
74#[derive(Debug, Deserialize, Serialize)]
75pub struct HTTPValidationError {
76 pub detail: Vec<ValidationError>,
77}
78
79#[derive(Debug, Clone, Deserialize, Serialize)]
80pub struct ValidationError {
81 pub msg: String,
82 pub loc: Vec<String>,
83}