// @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;

#[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> {
    ///Horizontal alignment
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub alignment: Option<CowStr<'a>>,
    ///Comparison caption
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub caption: Option<CowStr<'a>>,
    ///Exactly 2 images for comparison [before, after]
    #[serde(borrow)]
    pub images: Vec<GridImage<'a>>,
    ///Labels for the images [before label, after label]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub labels: Option<Vec<CowStr<'a>>>,
    ///CSS width value
    #[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 {}
    }
    /// 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<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>;
    }
    /// 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<'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> {
    /// Create a new builder for this type
    pub fn new() -> ImageDiffBuilder<'a, image_diff_state::Empty> {
        ImageDiffBuilder::new()
    }
}

impl<'a> ImageDiffBuilder<'a, 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),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: image_diff_state::State> ImageDiffBuilder<'a, S> {
    /// Set the `alignment` field (optional)
    pub fn alignment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `alignment` field to an Option value (optional)
    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> {
    /// Set the `caption` field (optional)
    pub fn caption(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `caption` field to an Option value (optional)
    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,
{
    /// Set the `images` field (required)
    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> {
    /// Set the `labels` field (optional)
    pub fn labels(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: image_diff_state::State> ImageDiffBuilder<'a, S> {
    /// Set the `width` field (optional)
    pub fn width(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `width` field to an Option value (optional)
    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,
{
    /// Build the final struct
    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(),
        }
    }
    /// Build the final struct with custom extra_data
    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()
    }
}