1#[derive(Clone, Debug)]
11#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
12pub struct File {
13 pub created: stripe_types::Timestamp,
15 pub expires_at: Option<stripe_types::Timestamp>,
17 pub filename: Option<String>,
19 pub id: stripe_shared::FileId,
21 pub links: Option<stripe_types::List<stripe_shared::FileLink>>,
23 pub purpose: stripe_shared::FilePurpose,
25 pub size: u64,
27 pub title: Option<String>,
29 #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
31 pub type_: Option<String>,
32 pub url: Option<String>,
34}
35#[doc(hidden)]
36pub struct FileBuilder {
37 created: Option<stripe_types::Timestamp>,
38 expires_at: Option<Option<stripe_types::Timestamp>>,
39 filename: Option<Option<String>>,
40 id: Option<stripe_shared::FileId>,
41 links: Option<Option<stripe_types::List<stripe_shared::FileLink>>>,
42 purpose: Option<stripe_shared::FilePurpose>,
43 size: Option<u64>,
44 title: Option<Option<String>>,
45 type_: Option<Option<String>>,
46 url: Option<Option<String>>,
47}
48
49#[allow(
50 unused_variables,
51 irrefutable_let_patterns,
52 clippy::let_unit_value,
53 clippy::match_single_binding,
54 clippy::single_match
55)]
56const _: () = {
57 use miniserde::de::{Map, Visitor};
58 use miniserde::json::Value;
59 use miniserde::{make_place, Deserialize, Result};
60 use stripe_types::miniserde_helpers::FromValueOpt;
61 use stripe_types::{MapBuilder, ObjectDeser};
62
63 make_place!(Place);
64
65 impl Deserialize for File {
66 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
67 Place::new(out)
68 }
69 }
70
71 struct Builder<'a> {
72 out: &'a mut Option<File>,
73 builder: FileBuilder,
74 }
75
76 impl Visitor for Place<File> {
77 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
78 Ok(Box::new(Builder { out: &mut self.out, builder: FileBuilder::deser_default() }))
79 }
80 }
81
82 impl MapBuilder for FileBuilder {
83 type Out = File;
84 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85 Ok(match k {
86 "created" => Deserialize::begin(&mut self.created),
87 "expires_at" => Deserialize::begin(&mut self.expires_at),
88 "filename" => Deserialize::begin(&mut self.filename),
89 "id" => Deserialize::begin(&mut self.id),
90 "links" => Deserialize::begin(&mut self.links),
91 "purpose" => Deserialize::begin(&mut self.purpose),
92 "size" => Deserialize::begin(&mut self.size),
93 "title" => Deserialize::begin(&mut self.title),
94 "type" => Deserialize::begin(&mut self.type_),
95 "url" => Deserialize::begin(&mut self.url),
96
97 _ => <dyn Visitor>::ignore(),
98 })
99 }
100
101 fn deser_default() -> Self {
102 Self {
103 created: Deserialize::default(),
104 expires_at: Deserialize::default(),
105 filename: Deserialize::default(),
106 id: Deserialize::default(),
107 links: Deserialize::default(),
108 purpose: Deserialize::default(),
109 size: Deserialize::default(),
110 title: Deserialize::default(),
111 type_: Deserialize::default(),
112 url: Deserialize::default(),
113 }
114 }
115
116 fn take_out(&mut self) -> Option<Self::Out> {
117 let (
118 Some(created),
119 Some(expires_at),
120 Some(filename),
121 Some(id),
122 Some(links),
123 Some(purpose),
124 Some(size),
125 Some(title),
126 Some(type_),
127 Some(url),
128 ) = (
129 self.created,
130 self.expires_at,
131 self.filename.take(),
132 self.id.take(),
133 self.links.take(),
134 self.purpose.take(),
135 self.size,
136 self.title.take(),
137 self.type_.take(),
138 self.url.take(),
139 )
140 else {
141 return None;
142 };
143 Some(Self::Out {
144 created,
145 expires_at,
146 filename,
147 id,
148 links,
149 purpose,
150 size,
151 title,
152 type_,
153 url,
154 })
155 }
156 }
157
158 impl Map for Builder<'_> {
159 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
160 self.builder.key(k)
161 }
162
163 fn finish(&mut self) -> Result<()> {
164 *self.out = self.builder.take_out();
165 Ok(())
166 }
167 }
168
169 impl ObjectDeser for File {
170 type Builder = FileBuilder;
171 }
172
173 impl FromValueOpt for File {
174 fn from_value(v: Value) -> Option<Self> {
175 let Value::Object(obj) = v else {
176 return None;
177 };
178 let mut b = FileBuilder::deser_default();
179 for (k, v) in obj {
180 match k.as_str() {
181 "created" => b.created = FromValueOpt::from_value(v),
182 "expires_at" => b.expires_at = FromValueOpt::from_value(v),
183 "filename" => b.filename = FromValueOpt::from_value(v),
184 "id" => b.id = FromValueOpt::from_value(v),
185 "links" => b.links = FromValueOpt::from_value(v),
186 "purpose" => b.purpose = FromValueOpt::from_value(v),
187 "size" => b.size = FromValueOpt::from_value(v),
188 "title" => b.title = FromValueOpt::from_value(v),
189 "type" => b.type_ = FromValueOpt::from_value(v),
190 "url" => b.url = FromValueOpt::from_value(v),
191
192 _ => {}
193 }
194 }
195 b.take_out()
196 }
197 }
198};
199#[cfg(feature = "serialize")]
200impl serde::Serialize for File {
201 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
202 use serde::ser::SerializeStruct;
203 let mut s = s.serialize_struct("File", 11)?;
204 s.serialize_field("created", &self.created)?;
205 s.serialize_field("expires_at", &self.expires_at)?;
206 s.serialize_field("filename", &self.filename)?;
207 s.serialize_field("id", &self.id)?;
208 s.serialize_field("links", &self.links)?;
209 s.serialize_field("purpose", &self.purpose)?;
210 s.serialize_field("size", &self.size)?;
211 s.serialize_field("title", &self.title)?;
212 s.serialize_field("type", &self.type_)?;
213 s.serialize_field("url", &self.url)?;
214
215 s.serialize_field("object", "file")?;
216 s.end()
217 }
218}
219impl stripe_types::Object for File {
220 type Id = stripe_shared::FileId;
221 fn id(&self) -> &Self::Id {
222 &self.id
223 }
224
225 fn into_id(self) -> Self::Id {
226 self.id
227 }
228}
229stripe_types::def_id!(FileId);
230#[derive(Clone, Eq, PartialEq)]
231#[non_exhaustive]
232pub enum FilePurpose {
233 AccountRequirement,
234 AdditionalVerification,
235 BusinessIcon,
236 BusinessLogo,
237 CustomerSignature,
238 DisputeEvidence,
239 DocumentProviderIdentityDocument,
240 FinanceReportRun,
241 FinancialAccountStatement,
242 IdentityDocument,
243 IdentityDocumentDownloadable,
244 IssuingRegulatoryReporting,
245 PciDocument,
246 Selfie,
247 SigmaScheduledQuery,
248 TaxDocumentUserUpload,
249 TerminalAndroidApk,
250 TerminalReaderSplashscreen,
251 Unknown(String),
253}
254impl FilePurpose {
255 pub fn as_str(&self) -> &str {
256 use FilePurpose::*;
257 match self {
258 AccountRequirement => "account_requirement",
259 AdditionalVerification => "additional_verification",
260 BusinessIcon => "business_icon",
261 BusinessLogo => "business_logo",
262 CustomerSignature => "customer_signature",
263 DisputeEvidence => "dispute_evidence",
264 DocumentProviderIdentityDocument => "document_provider_identity_document",
265 FinanceReportRun => "finance_report_run",
266 FinancialAccountStatement => "financial_account_statement",
267 IdentityDocument => "identity_document",
268 IdentityDocumentDownloadable => "identity_document_downloadable",
269 IssuingRegulatoryReporting => "issuing_regulatory_reporting",
270 PciDocument => "pci_document",
271 Selfie => "selfie",
272 SigmaScheduledQuery => "sigma_scheduled_query",
273 TaxDocumentUserUpload => "tax_document_user_upload",
274 TerminalAndroidApk => "terminal_android_apk",
275 TerminalReaderSplashscreen => "terminal_reader_splashscreen",
276 Unknown(v) => v,
277 }
278 }
279}
280
281impl std::str::FromStr for FilePurpose {
282 type Err = std::convert::Infallible;
283 fn from_str(s: &str) -> Result<Self, Self::Err> {
284 use FilePurpose::*;
285 match s {
286 "account_requirement" => Ok(AccountRequirement),
287 "additional_verification" => Ok(AdditionalVerification),
288 "business_icon" => Ok(BusinessIcon),
289 "business_logo" => Ok(BusinessLogo),
290 "customer_signature" => Ok(CustomerSignature),
291 "dispute_evidence" => Ok(DisputeEvidence),
292 "document_provider_identity_document" => Ok(DocumentProviderIdentityDocument),
293 "finance_report_run" => Ok(FinanceReportRun),
294 "financial_account_statement" => Ok(FinancialAccountStatement),
295 "identity_document" => Ok(IdentityDocument),
296 "identity_document_downloadable" => Ok(IdentityDocumentDownloadable),
297 "issuing_regulatory_reporting" => Ok(IssuingRegulatoryReporting),
298 "pci_document" => Ok(PciDocument),
299 "selfie" => Ok(Selfie),
300 "sigma_scheduled_query" => Ok(SigmaScheduledQuery),
301 "tax_document_user_upload" => Ok(TaxDocumentUserUpload),
302 "terminal_android_apk" => Ok(TerminalAndroidApk),
303 "terminal_reader_splashscreen" => Ok(TerminalReaderSplashscreen),
304 v => Ok(Unknown(v.to_owned())),
305 }
306 }
307}
308impl std::fmt::Display for FilePurpose {
309 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
310 f.write_str(self.as_str())
311 }
312}
313
314impl std::fmt::Debug for FilePurpose {
315 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
316 f.write_str(self.as_str())
317 }
318}
319impl serde::Serialize for FilePurpose {
320 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
321 where
322 S: serde::Serializer,
323 {
324 serializer.serialize_str(self.as_str())
325 }
326}
327impl miniserde::Deserialize for FilePurpose {
328 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
329 crate::Place::new(out)
330 }
331}
332
333impl miniserde::de::Visitor for crate::Place<FilePurpose> {
334 fn string(&mut self, s: &str) -> miniserde::Result<()> {
335 use std::str::FromStr;
336 self.out = Some(FilePurpose::from_str(s).unwrap());
337 Ok(())
338 }
339}
340
341stripe_types::impl_from_val_with_from_str!(FilePurpose);
342#[cfg(feature = "deserialize")]
343impl<'de> serde::Deserialize<'de> for FilePurpose {
344 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
345 use std::str::FromStr;
346 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
347 Ok(Self::from_str(&s).unwrap())
348 }
349}