use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize)]
pub struct BatchRequestCounts {
#[serde(default)]
pub total: Option<i64>,
#[serde(default)]
pub completed: Option<i64>,
#[serde(default)]
pub failed: Option<i64>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Batch {
pub id: String,
#[serde(default)]
pub object: Option<String>,
#[serde(default)]
pub endpoint: Option<String>,
#[serde(default)]
pub status: Option<String>,
#[serde(default)]
pub input_file_id: Option<String>,
#[serde(default)]
pub output_file_id: Option<String>,
#[serde(default)]
pub error_file_id: Option<String>,
#[serde(default)]
pub created_at: Option<i64>,
#[serde(default)]
pub completed_at: Option<i64>,
#[serde(default)]
pub request_counts: Option<BatchRequestCounts>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct BatchList {
#[serde(default)]
pub object: Option<String>,
#[serde(default)]
pub data: Vec<Batch>,
#[serde(default)]
pub has_more: Option<bool>,
}
#[derive(Debug, Clone, Serialize)]
pub struct BatchCreateParams {
pub input_file_id: String,
pub endpoint: String,
pub completion_window: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, String>>,
}
#[derive(Debug, Clone, Default)]
pub struct BatchListParams {
pub limit: Option<u32>,
pub after: Option<String>,
}
impl BatchListParams {
pub(crate) fn query(&self) -> Vec<(String, String)> {
let mut q = Vec::new();
if let Some(l) = self.limit {
q.push(("limit".to_owned(), l.to_string()));
}
if let Some(a) = &self.after {
q.push(("after".to_owned(), a.clone()));
}
q
}
}