1use serde::{Deserialize, Serialize};
2use validator::Validate;
3
4#[derive(Debug, Clone, Serialize, Validate)]
5pub struct FileListQuery {
6 #[serde(skip_serializing_if = "Option::is_none")]
8 pub after: Option<String>,
9
10 #[serde(skip_serializing_if = "Option::is_none")]
12 pub purpose: Option<FilePurpose>,
13
14 #[serde(skip_serializing_if = "Option::is_none")]
16 pub order: Option<FileOrder>,
17
18 #[serde(skip_serializing_if = "Option::is_none")]
20 #[validate(range(min = 1, max = 100))]
21 pub limit: Option<u32>,
22}
23
24impl Default for FileListQuery {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30impl FileListQuery {
31 pub fn new() -> Self {
32 Self {
33 after: None,
34 purpose: None,
35 order: None,
36 limit: None,
37 }
38 }
39 pub fn with_after(mut self, after: impl Into<String>) -> Self {
40 self.after = Some(after.into());
41 self
42 }
43 pub fn with_purpose(mut self, p: FilePurpose) -> Self {
44 self.purpose = Some(p);
45 self
46 }
47 pub fn with_order(mut self, o: FileOrder) -> Self {
48 self.order = Some(o);
49 self
50 }
51 pub fn with_limit(mut self, limit: u32) -> Self {
52 self.limit = Some(limit);
53 self
54 }
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub enum FilePurpose {
59 #[serde(rename = "batch")]
60 Batch,
61 #[serde(rename = "file-extract")]
62 FileExtract,
63 #[serde(rename = "code-interpreter")]
64 CodeInterpreter,
65 #[serde(rename = "agent")]
66 Agent,
67 #[serde(rename = "voice-clone-input")]
68 VoiceCloneInput,
69}
70
71impl FilePurpose {
72 pub fn as_str(&self) -> &'static str {
73 match self {
74 FilePurpose::Batch => "batch",
75 FilePurpose::FileExtract => "file-extract",
76 FilePurpose::CodeInterpreter => "code-interpreter",
77 FilePurpose::Agent => "agent",
78 FilePurpose::VoiceCloneInput => "voice-clone-input",
79 }
80 }
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub enum FileOrder {
85 #[serde(rename = "created_at")]
86 CreatedAt,
87}
88
89impl FileOrder {
90 pub fn as_str(&self) -> &'static str {
91 match self {
92 FileOrder::CreatedAt => "created_at",
93 }
94 }
95}