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::{Deserialize, Result, make_place};
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 _ => <dyn Visitor>::ignore(),
97 })
98 }
99
100 fn deser_default() -> Self {
101 Self {
102 created: Deserialize::default(),
103 expires_at: Deserialize::default(),
104 filename: Deserialize::default(),
105 id: Deserialize::default(),
106 links: Deserialize::default(),
107 purpose: Deserialize::default(),
108 size: Deserialize::default(),
109 title: Deserialize::default(),
110 type_: Deserialize::default(),
111 url: Deserialize::default(),
112 }
113 }
114
115 fn take_out(&mut self) -> Option<Self::Out> {
116 let (
117 Some(created),
118 Some(expires_at),
119 Some(filename),
120 Some(id),
121 Some(links),
122 Some(purpose),
123 Some(size),
124 Some(title),
125 Some(type_),
126 Some(url),
127 ) = (
128 self.created,
129 self.expires_at,
130 self.filename.take(),
131 self.id.take(),
132 self.links.take(),
133 self.purpose.take(),
134 self.size,
135 self.title.take(),
136 self.type_.take(),
137 self.url.take(),
138 )
139 else {
140 return None;
141 };
142 Some(Self::Out {
143 created,
144 expires_at,
145 filename,
146 id,
147 links,
148 purpose,
149 size,
150 title,
151 type_,
152 url,
153 })
154 }
155 }
156
157 impl Map for Builder<'_> {
158 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
159 self.builder.key(k)
160 }
161
162 fn finish(&mut self) -> Result<()> {
163 *self.out = self.builder.take_out();
164 Ok(())
165 }
166 }
167
168 impl ObjectDeser for File {
169 type Builder = FileBuilder;
170 }
171
172 impl FromValueOpt for File {
173 fn from_value(v: Value) -> Option<Self> {
174 let Value::Object(obj) = v else {
175 return None;
176 };
177 let mut b = FileBuilder::deser_default();
178 for (k, v) in obj {
179 match k.as_str() {
180 "created" => b.created = FromValueOpt::from_value(v),
181 "expires_at" => b.expires_at = FromValueOpt::from_value(v),
182 "filename" => b.filename = FromValueOpt::from_value(v),
183 "id" => b.id = FromValueOpt::from_value(v),
184 "links" => b.links = FromValueOpt::from_value(v),
185 "purpose" => b.purpose = FromValueOpt::from_value(v),
186 "size" => b.size = FromValueOpt::from_value(v),
187 "title" => b.title = FromValueOpt::from_value(v),
188 "type" => b.type_ = FromValueOpt::from_value(v),
189 "url" => b.url = FromValueOpt::from_value(v),
190 _ => {}
191 }
192 }
193 b.take_out()
194 }
195 }
196};
197#[cfg(feature = "serialize")]
198impl serde::Serialize for File {
199 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
200 use serde::ser::SerializeStruct;
201 let mut s = s.serialize_struct("File", 11)?;
202 s.serialize_field("created", &self.created)?;
203 s.serialize_field("expires_at", &self.expires_at)?;
204 s.serialize_field("filename", &self.filename)?;
205 s.serialize_field("id", &self.id)?;
206 s.serialize_field("links", &self.links)?;
207 s.serialize_field("purpose", &self.purpose)?;
208 s.serialize_field("size", &self.size)?;
209 s.serialize_field("title", &self.title)?;
210 s.serialize_field("type", &self.type_)?;
211 s.serialize_field("url", &self.url)?;
212
213 s.serialize_field("object", "file")?;
214 s.end()
215 }
216}
217impl stripe_types::Object for File {
218 type Id = stripe_shared::FileId;
219 fn id(&self) -> &Self::Id {
220 &self.id
221 }
222
223 fn into_id(self) -> Self::Id {
224 self.id
225 }
226}
227stripe_types::def_id!(FileId);
228#[derive(Clone, Eq, PartialEq)]
229#[non_exhaustive]
230pub enum FilePurpose {
231 AccountRequirement,
232 AdditionalVerification,
233 BusinessIcon,
234 BusinessLogo,
235 CustomerSignature,
236 DisputeEvidence,
237 DocumentProviderIdentityDocument,
238 FinanceReportRun,
239 FinancialAccountStatement,
240 IdentityDocument,
241 IdentityDocumentDownloadable,
242 IssuingRegulatoryReporting,
243 PciDocument,
244 PlatformTermsOfService,
245 Selfie,
246 SigmaScheduledQuery,
247 TaxDocumentUserUpload,
248 TerminalAndroidApk,
249 TerminalReaderSplashscreen,
250 Unknown(String),
252}
253impl FilePurpose {
254 pub fn as_str(&self) -> &str {
255 use FilePurpose::*;
256 match self {
257 AccountRequirement => "account_requirement",
258 AdditionalVerification => "additional_verification",
259 BusinessIcon => "business_icon",
260 BusinessLogo => "business_logo",
261 CustomerSignature => "customer_signature",
262 DisputeEvidence => "dispute_evidence",
263 DocumentProviderIdentityDocument => "document_provider_identity_document",
264 FinanceReportRun => "finance_report_run",
265 FinancialAccountStatement => "financial_account_statement",
266 IdentityDocument => "identity_document",
267 IdentityDocumentDownloadable => "identity_document_downloadable",
268 IssuingRegulatoryReporting => "issuing_regulatory_reporting",
269 PciDocument => "pci_document",
270 PlatformTermsOfService => "platform_terms_of_service",
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 "platform_terms_of_service" => Ok(PlatformTermsOfService),
300 "selfie" => Ok(Selfie),
301 "sigma_scheduled_query" => Ok(SigmaScheduledQuery),
302 "tax_document_user_upload" => Ok(TaxDocumentUserUpload),
303 "terminal_android_apk" => Ok(TerminalAndroidApk),
304 "terminal_reader_splashscreen" => Ok(TerminalReaderSplashscreen),
305 v => Ok(Unknown(v.to_owned())),
306 }
307 }
308}
309impl std::fmt::Display for FilePurpose {
310 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
311 f.write_str(self.as_str())
312 }
313}
314
315impl std::fmt::Debug for FilePurpose {
316 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
317 f.write_str(self.as_str())
318 }
319}
320impl serde::Serialize for FilePurpose {
321 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
322 where
323 S: serde::Serializer,
324 {
325 serializer.serialize_str(self.as_str())
326 }
327}
328impl miniserde::Deserialize for FilePurpose {
329 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
330 crate::Place::new(out)
331 }
332}
333
334impl miniserde::de::Visitor for crate::Place<FilePurpose> {
335 fn string(&mut self, s: &str) -> miniserde::Result<()> {
336 use std::str::FromStr;
337 self.out = Some(FilePurpose::from_str(s).unwrap());
338 Ok(())
339 }
340}
341
342stripe_types::impl_from_val_with_from_str!(FilePurpose);
343#[cfg(feature = "deserialize")]
344impl<'de> serde::Deserialize<'de> for FilePurpose {
345 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
346 use std::str::FromStr;
347 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
348 Ok(Self::from_str(&s).unwrap())
349 }
350}