// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.offprint.block.imageCarousel
//
// 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 ImageCarousel<S: BosStr = DefaultStr> {
    ///Auto-advance slides  Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_image_carousel_autoplay")]
    pub autoplay: Option<bool>,
    ///Carousel caption
    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<S>,
    ///Array of images in the carousel (2-6)
    pub images: Vec<GridImage<S>>,
    ///Milliseconds between slides  Defaults to `3000`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_image_carousel_interval")]
    pub interval: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ImageCarousel<S> {
    fn nsid() -> &'static str {
        "app.offprint.block.imageCarousel"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_offprint_block_imageCarousel()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.images;
            #[allow(unused_comparisons)]
            if value.len() > 6usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("images"),
                    max: 6usize,
                    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(),
                });
            }
        }
        Ok(())
    }
}

fn _default_image_carousel_autoplay() -> Option<bool> {
    Some(false)
}

fn _default_image_carousel_interval() -> Option<i64> {
    Some(3000i64)
}

pub mod image_carousel_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 ImageCarouselBuilder<
    St: image_carousel_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<bool>, Option<S>, Option<Vec<GridImage<S>>>, Option<i64>),
    _type: PhantomData<fn() -> S>,
}

impl ImageCarousel<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> ImageCarouselBuilder<image_carousel_state::Empty, DefaultStr> {
        ImageCarouselBuilder::new()
    }
}

impl<S: BosStr> ImageCarousel<S> {
    /// Create a new builder for this type
    pub fn builder() -> ImageCarouselBuilder<image_carousel_state::Empty, S> {
        ImageCarouselBuilder::builder()
    }
}

impl ImageCarouselBuilder<image_carousel_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        ImageCarouselBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

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

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

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

impl<St: image_carousel_state::State, S: BosStr> ImageCarouselBuilder<St, S> {
    /// Set the `interval` field (optional)
    pub fn interval(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `interval` field to an Option value (optional)
    pub fn maybe_interval(mut self, value: Option<i64>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> ImageCarouselBuilder<St, S>
where
    St: image_carousel_state::State,
    St::Images: image_carousel_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ImageCarousel<S> {
        ImageCarousel {
            autoplay: self._fields.0.or_else(|| Some(false)),
            caption: self._fields.1,
            images: self._fields.2.unwrap(),
            interval: self._fields.3.or_else(|| Some(3000i64)),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ImageCarousel<S> {
        ImageCarousel {
            autoplay: self._fields.0.or_else(|| Some(false)),
            caption: self._fields.1,
            images: self._fields.2.unwrap(),
            interval: self._fields.3.or_else(|| Some(3000i64)),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_offprint_block_imageCarousel() -> 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.imageCarousel"),
        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("autoplay"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("caption"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Carousel caption")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("images"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("Array of images in the carousel (2-6)"),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "app.offprint.block.imageGrid#gridImage",
                                    ),
                                    ..Default::default()
                                }),
                                min_length: Some(2usize),
                                max_length: Some(6usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("interval"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}