jacquard-api 0.12.0-beta.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.offprint.block.imageDiff
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ImageDiff<S: BosStr = DefaultStr> {
    ///Horizontal alignment
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alignment: Option<S>,
    ///Comparison caption
    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<S>,
    ///Exactly 2 images for comparison [before, after]
    pub images: Vec<GridImage<S>>,
    ///Labels for the images [before label, after label]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub labels: Option<Vec<S>>,
    ///CSS width value
    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ImageDiff<S> {
    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 {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Images;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Images = Unset;
    }
    ///State transition - sets the `images` field to Set
    pub struct SetImages<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetImages<St> {}
    impl<St: State> State for SetImages<St> {
        type Images = Set<members::images>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `images` field
        pub struct images(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ImageDiffBuilder<S: BosStr, St: image_diff_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<S>,
        Option<Vec<GridImage<S>>>,
        Option<Vec<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl<S: BosStr> ImageDiff<S> {
    /// Create a new builder for this type.
    pub fn new() -> ImageDiffBuilder<S, image_diff_state::Empty> {
        ImageDiffBuilder::new()
    }
}

impl<S: BosStr> ImageDiffBuilder<S, image_diff_state::Empty> {
    /// Create a new builder with all fields unset.
    pub fn new() -> Self {
        ImageDiffBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: image_diff_state::State> ImageDiffBuilder<S, St> {
    /// Set the `alignment` field (optional)
    pub fn alignment(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `alignment` field to an Option value (optional)
    pub fn maybe_alignment(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<S: BosStr, St: image_diff_state::State> ImageDiffBuilder<S, St> {
    /// Set the `caption` field (optional)
    pub fn caption(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `caption` field to an Option value (optional)
    pub fn maybe_caption(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<S: BosStr, St> ImageDiffBuilder<S, St>
where
    St: image_diff_state::State,
    St::Images: image_diff_state::IsUnset,
{
    /// Set the `images` field (required)
    pub fn images(
        mut self,
        value: impl Into<Vec<GridImage<S>>>,
    ) -> ImageDiffBuilder<S, image_diff_state::SetImages<St>> {
        self._fields.2 = Option::Some(value.into());
        ImageDiffBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: image_diff_state::State> ImageDiffBuilder<S, St> {
    /// Set the `labels` field (optional)
    pub fn labels(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `labels` field to an Option value (optional)
    pub fn maybe_labels(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<S: BosStr, St: image_diff_state::State> ImageDiffBuilder<S, St> {
    /// Set the `width` field (optional)
    pub fn width(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `width` field to an Option value (optional)
    pub fn maybe_width(mut self, value: Option<S>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<S: BosStr, St> ImageDiffBuilder<S, St>
where
    St: image_diff_state::State,
    St::Images: image_diff_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ImageDiff<S> {
        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(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ImageDiff<S> {
        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()
    }
}