1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Deserialize)]
7pub struct BatchRequestCounts {
8 #[serde(default)]
10 pub total: Option<i64>,
11 #[serde(default)]
13 pub completed: Option<i64>,
14 #[serde(default)]
16 pub failed: Option<i64>,
17}
18
19#[derive(Debug, Clone, Deserialize)]
22pub struct Batch {
23 pub id: String,
25 #[serde(default)]
27 pub object: Option<String>,
28 #[serde(default)]
30 pub endpoint: Option<String>,
31 #[serde(default)]
33 pub status: Option<String>,
34 #[serde(default)]
36 pub input_file_id: Option<String>,
37 #[serde(default)]
39 pub output_file_id: Option<String>,
40 #[serde(default)]
42 pub error_file_id: Option<String>,
43 #[serde(default)]
45 pub created_at: Option<i64>,
46 #[serde(default)]
48 pub completed_at: Option<i64>,
49 #[serde(default)]
51 pub request_counts: Option<BatchRequestCounts>,
52}
53
54#[derive(Debug, Clone, Deserialize)]
56pub struct BatchList {
57 #[serde(default)]
59 pub object: Option<String>,
60 #[serde(default)]
62 pub data: Vec<Batch>,
63 #[serde(default)]
65 pub has_more: Option<bool>,
66}
67
68#[derive(Debug, Clone, Serialize)]
70pub struct BatchCreateParams {
71 pub input_file_id: String,
73 pub endpoint: String,
75 pub completion_window: String,
77 #[serde(skip_serializing_if = "Option::is_none")]
79 pub metadata: Option<HashMap<String, String>>,
80}
81
82#[derive(Debug, Clone, Default)]
84pub struct BatchListParams {
85 pub limit: Option<u32>,
87 pub after: Option<String>,
89}
90
91impl BatchListParams {
92 pub(crate) fn query(&self) -> Vec<(String, String)> {
93 let mut q = Vec::new();
94 if let Some(l) = self.limit {
95 q.push(("limit".to_owned(), l.to_string()));
96 }
97 if let Some(a) = &self.after {
98 q.push(("after".to_owned(), a.clone()));
99 }
100 q
101 }
102}