#[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_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};
use crate::app_offprint::block::image_grid::GridImage;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ImageDiff<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub alignment: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub caption: Option<CowStr<'a>>,
#[serde(borrow)]
pub images: Vec<GridImage<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub labels: Option<Vec<CowStr<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub width: Option<CowStr<'a>>,
}
impl<'a> LexiconSchema for ImageDiff<'a> {
fn nsid() -> &'static str {
"app.offprint.block.imageDiff"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_offprint_block_imageDiff()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.images;
#[allow(unused_comparisons)]
if value.len() > 2usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("images"),
max: 2usize,
actual: value.len(),
});
}
}
{
let value = &self.images;
#[allow(unused_comparisons)]
if value.len() < 2usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("images"),
min: 2usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.labels {
#[allow(unused_comparisons)]
if value.len() > 2usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("labels"),
max: 2usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.labels {
#[allow(unused_comparisons)]
if value.len() < 2usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("labels"),
min: 2usize,
actual: value.len(),
});
}
}
Ok(())
}
}
pub mod image_diff_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 Images;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Images = Unset;
}
pub struct SetImages<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetImages<S> {}
impl<S: State> State for SetImages<S> {
type Images = Set<members::images>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct images(());
}
}
pub struct ImageDiffBuilder<'a, S: image_diff_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<Vec<GridImage<'a>>>,
Option<Vec<CowStr<'a>>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> ImageDiff<'a> {
pub fn new() -> ImageDiffBuilder<'a, image_diff_state::Empty> {
ImageDiffBuilder::new()
}
}
impl<'a> ImageDiffBuilder<'a, image_diff_state::Empty> {
pub fn new() -> Self {
ImageDiffBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: image_diff_state::State> ImageDiffBuilder<'a, S> {
pub fn alignment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_alignment(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: image_diff_state::State> ImageDiffBuilder<'a, S> {
pub fn caption(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_caption(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> ImageDiffBuilder<'a, S>
where
S: image_diff_state::State,
S::Images: image_diff_state::IsUnset,
{
pub fn images(
mut self,
value: impl Into<Vec<GridImage<'a>>>,
) -> ImageDiffBuilder<'a, image_diff_state::SetImages<S>> {
self._fields.2 = Option::Some(value.into());
ImageDiffBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: image_diff_state::State> ImageDiffBuilder<'a, S> {
pub fn labels(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_labels(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: image_diff_state::State> ImageDiffBuilder<'a, S> {
pub fn width(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_width(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S> ImageDiffBuilder<'a, S>
where
S: image_diff_state::State,
S::Images: image_diff_state::IsSet,
{
pub fn build(self) -> ImageDiff<'a> {
ImageDiff {
alignment: self._fields.0,
caption: self._fields.1,
images: self._fields.2.unwrap(),
labels: self._fields.3,
width: self._fields.4,
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>,
>,
) -> ImageDiff<'a> {
ImageDiff {
alignment: self._fields.0,
caption: self._fields.1,
images: self._fields.2.unwrap(),
labels: self._fields.3,
width: self._fields.4,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_offprint_block_imageDiff() -> 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("app.offprint.block.imageDiff"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("images")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("alignment"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Horizontal alignment"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("caption"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Comparison caption")),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("images"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Exactly 2 images for comparison [before, after]",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"app.offprint.block.imageGrid#gridImage",
),
..Default::default()
}),
min_length: Some(2usize),
max_length: Some(2usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("labels"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Labels for the images [before label, after label]",
),
),
items: LexArrayItem::String(LexString {
..Default::default()
}),
min_length: Some(2usize),
max_length: Some(2usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("width"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("CSS width value")),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}