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<'a> Map for Builder<'a> {
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 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 Selfie => "selfie",
271 SigmaScheduledQuery => "sigma_scheduled_query",
272 TaxDocumentUserUpload => "tax_document_user_upload",
273 TerminalReaderSplashscreen => "terminal_reader_splashscreen",
274 Unknown(v) => v,
275 }
276 }
277}
278
279impl std::str::FromStr for FilePurpose {
280 type Err = std::convert::Infallible;
281 fn from_str(s: &str) -> Result<Self, Self::Err> {
282 use FilePurpose::*;
283 match s {
284 "account_requirement" => Ok(AccountRequirement),
285 "additional_verification" => Ok(AdditionalVerification),
286 "business_icon" => Ok(BusinessIcon),
287 "business_logo" => Ok(BusinessLogo),
288 "customer_signature" => Ok(CustomerSignature),
289 "dispute_evidence" => Ok(DisputeEvidence),
290 "document_provider_identity_document" => Ok(DocumentProviderIdentityDocument),
291 "finance_report_run" => Ok(FinanceReportRun),
292 "financial_account_statement" => Ok(FinancialAccountStatement),
293 "identity_document" => Ok(IdentityDocument),
294 "identity_document_downloadable" => Ok(IdentityDocumentDownloadable),
295 "issuing_regulatory_reporting" => Ok(IssuingRegulatoryReporting),
296 "pci_document" => Ok(PciDocument),
297 "selfie" => Ok(Selfie),
298 "sigma_scheduled_query" => Ok(SigmaScheduledQuery),
299 "tax_document_user_upload" => Ok(TaxDocumentUserUpload),
300 "terminal_reader_splashscreen" => Ok(TerminalReaderSplashscreen),
301 v => Ok(Unknown(v.to_owned())),
302 }
303 }
304}
305impl std::fmt::Display for FilePurpose {
306 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
307 f.write_str(self.as_str())
308 }
309}
310
311impl std::fmt::Debug for FilePurpose {
312 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
313 f.write_str(self.as_str())
314 }
315}
316impl serde::Serialize for FilePurpose {
317 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
318 where
319 S: serde::Serializer,
320 {
321 serializer.serialize_str(self.as_str())
322 }
323}
324impl miniserde::Deserialize for FilePurpose {
325 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
326 crate::Place::new(out)
327 }
328}
329
330impl miniserde::de::Visitor for crate::Place<FilePurpose> {
331 fn string(&mut self, s: &str) -> miniserde::Result<()> {
332 use std::str::FromStr;
333 self.out = Some(FilePurpose::from_str(s).unwrap());
334 Ok(())
335 }
336}
337
338stripe_types::impl_from_val_with_from_str!(FilePurpose);
339#[cfg(feature = "deserialize")]
340impl<'de> serde::Deserialize<'de> for FilePurpose {
341 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
342 use std::str::FromStr;
343 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
344 Ok(Self::from_str(&s).unwrap())
345 }
346}