// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: site.standard.theme.color
//
// 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::{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};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Rgb<S: BosStr = DefaultStr> {
    pub b: i64,
    pub g: i64,
    pub r: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Rgba<S: BosStr = DefaultStr> {
    pub a: i64,
    pub b: i64,
    pub g: i64,
    pub r: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Rgb<S> {
    fn nsid() -> &'static str {
        "site.standard.theme.color"
    }
    fn def_name() -> &'static str {
        "rgb"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_site_standard_theme_color()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.b;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("b"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.b;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("b"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.g;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("g"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.g;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("g"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.r;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("r"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.r;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("r"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Rgba<S> {
    fn nsid() -> &'static str {
        "site.standard.theme.color"
    }
    fn def_name() -> &'static str {
        "rgba"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_site_standard_theme_color()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.a;
            if *value > 100i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("a"),
                    max: 100i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.a;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("a"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.b;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("b"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.b;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("b"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.g;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("g"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.g;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("g"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.r;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("r"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.r;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("r"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

pub mod rgb_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 B;
        type G;
        type R;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type B = Unset;
        type G = Unset;
        type R = Unset;
    }
    ///State transition - sets the `b` field to Set
    pub struct SetB<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetB<St> {}
    impl<St: State> State for SetB<St> {
        type B = Set<members::b>;
        type G = St::G;
        type R = St::R;
    }
    ///State transition - sets the `g` field to Set
    pub struct SetG<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetG<St> {}
    impl<St: State> State for SetG<St> {
        type B = St::B;
        type G = Set<members::g>;
        type R = St::R;
    }
    ///State transition - sets the `r` field to Set
    pub struct SetR<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetR<St> {}
    impl<St: State> State for SetR<St> {
        type B = St::B;
        type G = St::G;
        type R = Set<members::r>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `b` field
        pub struct b(());
        ///Marker type for the `g` field
        pub struct g(());
        ///Marker type for the `r` field
        pub struct r(());
    }
}

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

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

impl<S: BosStr> Rgb<S> {
    /// Create a new builder for this type
    pub fn builder() -> RgbBuilder<rgb_state::Empty, S> {
        RgbBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> RgbBuilder<St, S>
where
    St: rgb_state::State,
    St::B: rgb_state::IsUnset,
{
    /// Set the `b` field (required)
    pub fn b(mut self, value: impl Into<i64>) -> RgbBuilder<rgb_state::SetB<St>, S> {
        self._fields.0 = Option::Some(value.into());
        RgbBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RgbBuilder<St, S>
where
    St: rgb_state::State,
    St::G: rgb_state::IsUnset,
{
    /// Set the `g` field (required)
    pub fn g(mut self, value: impl Into<i64>) -> RgbBuilder<rgb_state::SetG<St>, S> {
        self._fields.1 = Option::Some(value.into());
        RgbBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RgbBuilder<St, S>
where
    St: rgb_state::State,
    St::R: rgb_state::IsUnset,
{
    /// Set the `r` field (required)
    pub fn r(mut self, value: impl Into<i64>) -> RgbBuilder<rgb_state::SetR<St>, S> {
        self._fields.2 = Option::Some(value.into());
        RgbBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RgbBuilder<St, S>
where
    St: rgb_state::State,
    St::B: rgb_state::IsSet,
    St::G: rgb_state::IsSet,
    St::R: rgb_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Rgb<S> {
        Rgb {
            b: self._fields.0.unwrap(),
            g: self._fields.1.unwrap(),
            r: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Rgb<S> {
        Rgb {
            b: self._fields.0.unwrap(),
            g: self._fields.1.unwrap(),
            r: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_site_standard_theme_color() -> 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("site.standard.theme.color"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("rgb"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("r"), SmolStr::new_static("g"),
                            SmolStr::new_static("b")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("b"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("g"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("r"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("rgba"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("r"), SmolStr::new_static("g"),
                            SmolStr::new_static("b"), SmolStr::new_static("a")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("a"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(100i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("b"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("g"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("r"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod rgba_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 A;
        type B;
        type G;
        type R;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type A = Unset;
        type B = Unset;
        type G = Unset;
        type R = Unset;
    }
    ///State transition - sets the `a` field to Set
    pub struct SetA<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetA<St> {}
    impl<St: State> State for SetA<St> {
        type A = Set<members::a>;
        type B = St::B;
        type G = St::G;
        type R = St::R;
    }
    ///State transition - sets the `b` field to Set
    pub struct SetB<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetB<St> {}
    impl<St: State> State for SetB<St> {
        type A = St::A;
        type B = Set<members::b>;
        type G = St::G;
        type R = St::R;
    }
    ///State transition - sets the `g` field to Set
    pub struct SetG<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetG<St> {}
    impl<St: State> State for SetG<St> {
        type A = St::A;
        type B = St::B;
        type G = Set<members::g>;
        type R = St::R;
    }
    ///State transition - sets the `r` field to Set
    pub struct SetR<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetR<St> {}
    impl<St: State> State for SetR<St> {
        type A = St::A;
        type B = St::B;
        type G = St::G;
        type R = Set<members::r>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `a` field
        pub struct a(());
        ///Marker type for the `b` field
        pub struct b(());
        ///Marker type for the `g` field
        pub struct g(());
        ///Marker type for the `r` field
        pub struct r(());
    }
}

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

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

impl<S: BosStr> Rgba<S> {
    /// Create a new builder for this type
    pub fn builder() -> RgbaBuilder<rgba_state::Empty, S> {
        RgbaBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> RgbaBuilder<St, S>
where
    St: rgba_state::State,
    St::A: rgba_state::IsUnset,
{
    /// Set the `a` field (required)
    pub fn a(mut self, value: impl Into<i64>) -> RgbaBuilder<rgba_state::SetA<St>, S> {
        self._fields.0 = Option::Some(value.into());
        RgbaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RgbaBuilder<St, S>
where
    St: rgba_state::State,
    St::B: rgba_state::IsUnset,
{
    /// Set the `b` field (required)
    pub fn b(mut self, value: impl Into<i64>) -> RgbaBuilder<rgba_state::SetB<St>, S> {
        self._fields.1 = Option::Some(value.into());
        RgbaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RgbaBuilder<St, S>
where
    St: rgba_state::State,
    St::G: rgba_state::IsUnset,
{
    /// Set the `g` field (required)
    pub fn g(mut self, value: impl Into<i64>) -> RgbaBuilder<rgba_state::SetG<St>, S> {
        self._fields.2 = Option::Some(value.into());
        RgbaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RgbaBuilder<St, S>
where
    St: rgba_state::State,
    St::R: rgba_state::IsUnset,
{
    /// Set the `r` field (required)
    pub fn r(mut self, value: impl Into<i64>) -> RgbaBuilder<rgba_state::SetR<St>, S> {
        self._fields.3 = Option::Some(value.into());
        RgbaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RgbaBuilder<St, S>
where
    St: rgba_state::State,
    St::A: rgba_state::IsSet,
    St::B: rgba_state::IsSet,
    St::G: rgba_state::IsSet,
    St::R: rgba_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Rgba<S> {
        Rgba {
            a: self._fields.0.unwrap(),
            b: self._fields.1.unwrap(),
            g: self._fields.2.unwrap(),
            r: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Rgba<S> {
        Rgba {
            a: self._fields.0.unwrap(),
            b: self._fields.1.unwrap(),
            g: self._fields.2.unwrap(),
            r: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}