// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: blog.pckt.theme
//
// 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::blog_pckt::theme;
/// Theme configuration for a blog publication

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Theme<S: BosStr = DefaultStr> {
    ///Dark mode color palette
    pub dark: theme::Palette<S>,
    ///Font family name (optional)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub font: Option<S>,
    ///Light mode color palette
    pub light: theme::Palette<S>,
    ///Content background transparency percentage (optional)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transparency: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Color palette with CSS hex values

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Palette<S: BosStr = DefaultStr> {
    ///Accent color (hex value)
    pub accent: S,
    ///Background color (hex value)
    pub background: S,
    ///Link color (hex value)
    pub link: S,
    ///Surface hover color (hex value)
    pub surface_hover: S,
    ///Primary text color (hex value)
    pub text: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Theme<S> {
    fn nsid() -> &'static str {
        "blog.pckt.theme"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blog_pckt_theme()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.font {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("font"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.transparency {
            if *value > 100i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("transparency"),
                    max: 100i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.transparency {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("transparency"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Palette<S> {
    fn nsid() -> &'static str {
        "blog.pckt.theme"
    }
    fn def_name() -> &'static str {
        "palette"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blog_pckt_theme()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.accent;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 7usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("accent"),
                    max: 7usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.background;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 7usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("background"),
                    max: 7usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.link;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 7usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("link"),
                    max: 7usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.surface_hover;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 7usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("surface_hover"),
                    max: 7usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 7usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 7usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod theme_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 Dark;
        type Light;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Dark = Unset;
        type Light = Unset;
    }
    ///State transition - sets the `dark` field to Set
    pub struct SetDark<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDark<St> {}
    impl<St: State> State for SetDark<St> {
        type Dark = Set<members::dark>;
        type Light = St::Light;
    }
    ///State transition - sets the `light` field to Set
    pub struct SetLight<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLight<St> {}
    impl<St: State> State for SetLight<St> {
        type Dark = St::Dark;
        type Light = Set<members::light>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `dark` field
        pub struct dark(());
        ///Marker type for the `light` field
        pub struct light(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ThemeBuilder<St: theme_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<theme::Palette<S>>,
        Option<S>,
        Option<theme::Palette<S>>,
        Option<i64>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Theme<S> {
    /// Create a new builder for this type
    pub fn builder() -> ThemeBuilder<theme_state::Empty, S> {
        ThemeBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ThemeBuilder<St, S>
where
    St: theme_state::State,
    St::Dark: theme_state::IsUnset,
{
    /// Set the `dark` field (required)
    pub fn dark(
        mut self,
        value: impl Into<theme::Palette<S>>,
    ) -> ThemeBuilder<theme_state::SetDark<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ThemeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ThemeBuilder<St, S>
where
    St: theme_state::State,
    St::Light: theme_state::IsUnset,
{
    /// Set the `light` field (required)
    pub fn light(
        mut self,
        value: impl Into<theme::Palette<S>>,
    ) -> ThemeBuilder<theme_state::SetLight<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ThemeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ThemeBuilder<St, S>
where
    St: theme_state::State,
    St::Dark: theme_state::IsSet,
    St::Light: theme_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Theme<S> {
        Theme {
            dark: self._fields.0.unwrap(),
            font: self._fields.1,
            light: self._fields.2.unwrap(),
            transparency: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Theme<S> {
        Theme {
            dark: self._fields.0.unwrap(),
            font: self._fields.1,
            light: self._fields.2.unwrap(),
            transparency: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_blog_pckt_theme() -> 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("blog.pckt.theme"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Theme configuration for a blog publication"),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("light"), SmolStr::new_static("dark")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("dark"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#palette"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("font"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Font family name (optional)"),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("light"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#palette"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("transparency"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(100i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("palette"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Color palette with CSS hex values"),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("link"), SmolStr::new_static("text"),
                            SmolStr::new_static("accent"),
                            SmolStr::new_static("background"),
                            SmolStr::new_static("surfaceHover")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("accent"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Accent color (hex value)"),
                                ),
                                max_length: Some(7usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("background"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Background color (hex value)"),
                                ),
                                max_length: Some(7usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("link"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Link color (hex value)"),
                                ),
                                max_length: Some(7usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("surfaceHover"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Surface hover color (hex value)"),
                                ),
                                max_length: Some(7usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Primary text color (hex value)"),
                                ),
                                max_length: Some(7usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}