#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::string::UriValue;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Website<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub preview_image: Option<BlobRef<'a>>,
#[serde(borrow)]
pub src: UriValue<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub title: Option<CowStr<'a>>,
}
impl<'a> LexiconSchema for Website<'a> {
fn nsid() -> &'static str {
"pub.leaflet.blocks.website"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_blocks_website()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.preview_image {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("preview_image"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.preview_image {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("preview_image"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
pub mod website_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Src;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Src = Unset;
}
pub struct SetSrc<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSrc<S> {}
impl<S: State> State for SetSrc<S> {
type Src = Set<members::src>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct src(());
}
}
pub struct WebsiteBuilder<'a, S: website_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<BlobRef<'a>>,
Option<UriValue<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Website<'a> {
pub fn new() -> WebsiteBuilder<'a, website_state::Empty> {
WebsiteBuilder::new()
}
}
impl<'a> WebsiteBuilder<'a, website_state::Empty> {
pub fn new() -> Self {
WebsiteBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: website_state::State> WebsiteBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: website_state::State> WebsiteBuilder<'a, S> {
pub fn preview_image(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_preview_image(mut self, value: Option<BlobRef<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> WebsiteBuilder<'a, S>
where
S: website_state::State,
S::Src: website_state::IsUnset,
{
pub fn src(
mut self,
value: impl Into<UriValue<'a>>,
) -> WebsiteBuilder<'a, website_state::SetSrc<S>> {
self._fields.2 = Option::Some(value.into());
WebsiteBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: website_state::State> WebsiteBuilder<'a, S> {
pub fn title(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> WebsiteBuilder<'a, S>
where
S: website_state::State,
S::Src: website_state::IsSet,
{
pub fn build(self) -> Website<'a> {
Website {
description: self._fields.0,
preview_image: self._fields.1,
src: self._fields.2.unwrap(),
title: self._fields.3,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Website<'a> {
Website {
description: self._fields.0,
preview_image: self._fields.1,
src: self._fields.2.unwrap(),
title: self._fields.3,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_pub_leaflet_blocks_website() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("pub.leaflet.blocks.website"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("src")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString { ..Default::default() }),
);
map.insert(
SmolStr::new_static("previewImage"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("src"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString { ..Default::default() }),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}