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 FileListQuery {
25 pub fn new() -> Self {
26 Self {
27 after: None,
28 purpose: None,
29 order: None,
30 limit: None,
31 }
32 }
33 pub fn with_after(mut self, after: impl Into<String>) -> Self {
34 self.after = Some(after.into());
35 self
36 }
37 pub fn with_purpose(mut self, p: FilePurpose) -> Self {
38 self.purpose = Some(p);
39 self
40 }
41 pub fn with_order(mut self, o: FileOrder) -> Self {
42 self.order = Some(o);
43 self
44 }
45 pub fn with_limit(mut self, limit: u32) -> Self {
46 self.limit = Some(limit);
47 self
48 }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub enum FilePurpose {
53 #[serde(rename = "batch")]
54 Batch,
55 #[serde(rename = "file-extract")]
56 FileExtract,
57 #[serde(rename = "code-interpreter")]
58 CodeInterpreter,
59 #[serde(rename = "agent")]
60 Agent,
61 #[serde(rename = "voice-clone-input")]
62 VoiceCloneInput,
63}
64
65impl FilePurpose {
66 pub fn as_str(&self) -> &'static str {
67 match self {
68 FilePurpose::Batch => "batch",
69 FilePurpose::FileExtract => "file-extract",
70 FilePurpose::CodeInterpreter => "code-interpreter",
71 FilePurpose::Agent => "agent",
72 FilePurpose::VoiceCloneInput => "voice-clone-input",
73 }
74 }
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub enum FileOrder {
79 #[serde(rename = "created_at")]
80 CreatedAt,
81}
82
83impl FileOrder {
84 pub fn as_str(&self) -> &'static str {
85 match self {
86 FileOrder::CreatedAt => "created_at",
87 }
88 }
89}