Skip to main content

jacquard_api/pub_leaflet/theme/
background_image.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: pub.leaflet.theme.backgroundImage
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13
14#[allow(unused_imports)]
15use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
16use jacquard_common::types::blob::BlobRef;
17use jacquard_derive::{IntoStatic, lexicon};
18use jacquard_lexicon::lexicon::LexiconDoc;
19use jacquard_lexicon::schema::LexiconSchema;
20
21#[allow(unused_imports)]
22use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
23use serde::{Serialize, Deserialize};
24
25#[lexicon]
26#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
27#[serde(rename_all = "camelCase")]
28pub struct BackgroundImage<'a> {
29    #[serde(borrow)]
30    pub image: BlobRef<'a>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub repeat: Option<bool>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub width: Option<i64>,
35}
36
37impl<'a> LexiconSchema for BackgroundImage<'a> {
38    fn nsid() -> &'static str {
39        "pub.leaflet.theme.backgroundImage"
40    }
41    fn def_name() -> &'static str {
42        "main"
43    }
44    fn lexicon_doc() -> LexiconDoc<'static> {
45        lexicon_doc_pub_leaflet_theme_backgroundImage()
46    }
47    fn validate(&self) -> Result<(), ConstraintError> {
48        {
49            let value = &self.image;
50            {
51                let size = value.blob().size;
52                if size > 1000000usize {
53                    return Err(ConstraintError::BlobTooLarge {
54                        path: ValidationPath::from_field("image"),
55                        max: 1000000usize,
56                        actual: size,
57                    });
58                }
59            }
60        }
61        {
62            let value = &self.image;
63            {
64                let mime = value.blob().mime_type.as_str();
65                let accepted: &[&str] = &["image/*"];
66                let matched = accepted
67                    .iter()
68                    .any(|pattern| {
69                        if *pattern == "*/*" {
70                            true
71                        } else if pattern.ends_with("/*") {
72                            let prefix = &pattern[..pattern.len() - 2];
73                            mime.starts_with(prefix)
74                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
75                        } else {
76                            mime == *pattern
77                        }
78                    });
79                if !matched {
80                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
81                        path: ValidationPath::from_field("image"),
82                        accepted: vec!["image/*".to_string()],
83                        actual: mime.to_string(),
84                    });
85                }
86            }
87        }
88        Ok(())
89    }
90}
91
92pub mod background_image_state {
93
94    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
95    #[allow(unused)]
96    use ::core::marker::PhantomData;
97    mod sealed {
98        pub trait Sealed {}
99    }
100    /// State trait tracking which required fields have been set
101    pub trait State: sealed::Sealed {
102        type Image;
103    }
104    /// Empty state - all required fields are unset
105    pub struct Empty(());
106    impl sealed::Sealed for Empty {}
107    impl State for Empty {
108        type Image = Unset;
109    }
110    ///State transition - sets the `image` field to Set
111    pub struct SetImage<S: State = Empty>(PhantomData<fn() -> S>);
112    impl<S: State> sealed::Sealed for SetImage<S> {}
113    impl<S: State> State for SetImage<S> {
114        type Image = Set<members::image>;
115    }
116    /// Marker types for field names
117    #[allow(non_camel_case_types)]
118    pub mod members {
119        ///Marker type for the `image` field
120        pub struct image(());
121    }
122}
123
124/// Builder for constructing an instance of this type
125pub struct BackgroundImageBuilder<'a, S: background_image_state::State> {
126    _state: PhantomData<fn() -> S>,
127    _fields: (Option<BlobRef<'a>>, Option<bool>, Option<i64>),
128    _lifetime: PhantomData<&'a ()>,
129}
130
131impl<'a> BackgroundImage<'a> {
132    /// Create a new builder for this type
133    pub fn new() -> BackgroundImageBuilder<'a, background_image_state::Empty> {
134        BackgroundImageBuilder::new()
135    }
136}
137
138impl<'a> BackgroundImageBuilder<'a, background_image_state::Empty> {
139    /// Create a new builder with all fields unset
140    pub fn new() -> Self {
141        BackgroundImageBuilder {
142            _state: PhantomData,
143            _fields: (None, None, None),
144            _lifetime: PhantomData,
145        }
146    }
147}
148
149impl<'a, S> BackgroundImageBuilder<'a, S>
150where
151    S: background_image_state::State,
152    S::Image: background_image_state::IsUnset,
153{
154    /// Set the `image` field (required)
155    pub fn image(
156        mut self,
157        value: impl Into<BlobRef<'a>>,
158    ) -> BackgroundImageBuilder<'a, background_image_state::SetImage<S>> {
159        self._fields.0 = Option::Some(value.into());
160        BackgroundImageBuilder {
161            _state: PhantomData,
162            _fields: self._fields,
163            _lifetime: PhantomData,
164        }
165    }
166}
167
168impl<'a, S: background_image_state::State> BackgroundImageBuilder<'a, S> {
169    /// Set the `repeat` field (optional)
170    pub fn repeat(mut self, value: impl Into<Option<bool>>) -> Self {
171        self._fields.1 = value.into();
172        self
173    }
174    /// Set the `repeat` field to an Option value (optional)
175    pub fn maybe_repeat(mut self, value: Option<bool>) -> Self {
176        self._fields.1 = value;
177        self
178    }
179}
180
181impl<'a, S: background_image_state::State> BackgroundImageBuilder<'a, S> {
182    /// Set the `width` field (optional)
183    pub fn width(mut self, value: impl Into<Option<i64>>) -> Self {
184        self._fields.2 = value.into();
185        self
186    }
187    /// Set the `width` field to an Option value (optional)
188    pub fn maybe_width(mut self, value: Option<i64>) -> Self {
189        self._fields.2 = value;
190        self
191    }
192}
193
194impl<'a, S> BackgroundImageBuilder<'a, S>
195where
196    S: background_image_state::State,
197    S::Image: background_image_state::IsSet,
198{
199    /// Build the final struct
200    pub fn build(self) -> BackgroundImage<'a> {
201        BackgroundImage {
202            image: self._fields.0.unwrap(),
203            repeat: self._fields.1,
204            width: self._fields.2,
205            extra_data: Default::default(),
206        }
207    }
208    /// Build the final struct with custom extra_data
209    pub fn build_with_data(
210        self,
211        extra_data: BTreeMap<
212            jacquard_common::deps::smol_str::SmolStr,
213            jacquard_common::types::value::Data<'a>,
214        >,
215    ) -> BackgroundImage<'a> {
216        BackgroundImage {
217            image: self._fields.0.unwrap(),
218            repeat: self._fields.1,
219            width: self._fields.2,
220            extra_data: Some(extra_data),
221        }
222    }
223}
224
225fn lexicon_doc_pub_leaflet_theme_backgroundImage() -> LexiconDoc<'static> {
226    #[allow(unused_imports)]
227    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
228    use jacquard_lexicon::lexicon::*;
229    use alloc::collections::BTreeMap;
230    LexiconDoc {
231        lexicon: Lexicon::Lexicon1,
232        id: CowStr::new_static("pub.leaflet.theme.backgroundImage"),
233        defs: {
234            let mut map = BTreeMap::new();
235            map.insert(
236                SmolStr::new_static("main"),
237                LexUserType::Object(LexObject {
238                    required: Some(vec![SmolStr::new_static("image")]),
239                    properties: {
240                        #[allow(unused_mut)]
241                        let mut map = BTreeMap::new();
242                        map.insert(
243                            SmolStr::new_static("image"),
244                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
245                        );
246                        map.insert(
247                            SmolStr::new_static("repeat"),
248                            LexObjectProperty::Boolean(LexBoolean {
249                                ..Default::default()
250                            }),
251                        );
252                        map.insert(
253                            SmolStr::new_static("width"),
254                            LexObjectProperty::Integer(LexInteger {
255                                ..Default::default()
256                            }),
257                        );
258                        map
259                    },
260                    ..Default::default()
261                }),
262            );
263            map
264        },
265        ..Default::default()
266    }
267}