// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.notebook.colourScheme
//
// 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
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};
/// A colour palette for notebook theming

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "sh.weaver.notebook.colourScheme",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ColourScheme<S: BosStr = DefaultStr> {
    pub colours: ColourSchemeColours<S>,
    ///Human-readable name for the colour scheme
    pub name: S,
    ///Whether this is a dark or light colour scheme
    pub variant: S,
    #[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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ColourSchemeColours<S: BosStr = DefaultStr> {
    ///Primary background for page/frame
    pub base: S,
    ///Border/divider colour
    pub border: S,
    ///Emphasized text (bold, important)
    pub emphasis: S,
    ///Error state colour
    pub error: S,
    ///Selection/highlight colour
    pub highlight: S,
    ///Hyperlink colour
    pub link: S,
    ///De-emphasized text (disabled, metadata)
    pub muted: S,
    ///Tertiary background for popovers/dialogs
    pub overlay: S,
    ///Primary brand/accent colour
    pub primary: S,
    ///Secondary accent colour
    pub secondary: S,
    ///Medium emphasis text (comments, labels)
    pub subtle: S,
    ///Success state colour
    pub success: S,
    ///Secondary background for panels/cards
    pub surface: S,
    ///Tertiary accent colour
    pub tertiary: S,
    ///Primary readable text colour
    pub text: S,
    ///Warning state colour
    pub warning: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ColourSchemeGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: ColourScheme<S>,
}

impl<S: BosStr> ColourScheme<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, ColourSchemeRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct ColourSchemeRecord;
impl XrpcResp for ColourSchemeRecord {
    const NSID: &'static str = "sh.weaver.notebook.colourScheme";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ColourSchemeGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<ColourSchemeGetRecordOutput<S>> for ColourScheme<S> {
    fn from(output: ColourSchemeGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for ColourScheme<S> {
    const NSID: &'static str = "sh.weaver.notebook.colourScheme";
    type Record = ColourSchemeRecord;
}

impl Collection for ColourSchemeRecord {
    const NSID: &'static str = "sh.weaver.notebook.colourScheme";
    type Record = ColourSchemeRecord;
}

impl<S: BosStr> LexiconSchema for ColourScheme<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notebook.colourScheme"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notebook_colourScheme()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ColourSchemeColours<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notebook.colourScheme"
    }
    fn def_name() -> &'static str {
        "ColourSchemeColours"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notebook_colourScheme()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_sh_weaver_notebook_colourScheme() -> 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("sh.weaver.notebook.colourScheme"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("A colour palette for notebook theming"),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"), SmolStr::new_static("variant"),
                                SmolStr::new_static("colours")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("colours"),
                                LexObjectProperty::Object(LexObject {
                                    required: Some(
                                        vec![
                                            SmolStr::new_static("base"), SmolStr::new_static("surface"),
                                            SmolStr::new_static("overlay"), SmolStr::new_static("text"),
                                            SmolStr::new_static("muted"), SmolStr::new_static("subtle"),
                                            SmolStr::new_static("emphasis"),
                                            SmolStr::new_static("primary"),
                                            SmolStr::new_static("secondary"),
                                            SmolStr::new_static("tertiary"),
                                            SmolStr::new_static("error"),
                                            SmolStr::new_static("warning"),
                                            SmolStr::new_static("success"),
                                            SmolStr::new_static("border"), SmolStr::new_static("link"),
                                            SmolStr::new_static("highlight")
                                        ],
                                    ),
                                    properties: {
                                        #[allow(unused_mut)]
                                        let mut map = BTreeMap::new();
                                        map.insert(
                                            SmolStr::new_static("base"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Primary background for page/frame"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("border"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Border/divider colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("emphasis"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Emphasized text (bold, important)"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("error"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(CowStr::new_static("Error state colour")),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("highlight"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Selection/highlight colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("link"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(CowStr::new_static("Hyperlink colour")),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("muted"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static(
                                                        "De-emphasized text (disabled, metadata)",
                                                    ),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("overlay"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static(
                                                        "Tertiary background for popovers/dialogs",
                                                    ),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("primary"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Primary brand/accent colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("secondary"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Secondary accent colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("subtle"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static(
                                                        "Medium emphasis text (comments, labels)",
                                                    ),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("success"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Success state colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("surface"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Secondary background for panels/cards"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("tertiary"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Tertiary accent colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("text"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Primary readable text colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map.insert(
                                            SmolStr::new_static("warning"),
                                            LexObjectProperty::String(LexString {
                                                description: Some(
                                                    CowStr::new_static("Warning state colour"),
                                                ),
                                                ..Default::default()
                                            }),
                                        );
                                        map
                                    },
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Human-readable name for the colour scheme",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("variant"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Whether this is a dark or light colour scheme",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod colour_scheme_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 Colours;
        type Name;
        type Variant;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Colours = Unset;
        type Name = Unset;
        type Variant = Unset;
    }
    ///State transition - sets the `colours` field to Set
    pub struct SetColours<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetColours<St> {}
    impl<St: State> State for SetColours<St> {
        type Colours = Set<members::colours>;
        type Name = St::Name;
        type Variant = St::Variant;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Colours = St::Colours;
        type Name = Set<members::name>;
        type Variant = St::Variant;
    }
    ///State transition - sets the `variant` field to Set
    pub struct SetVariant<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetVariant<St> {}
    impl<St: State> State for SetVariant<St> {
        type Colours = St::Colours;
        type Name = St::Name;
        type Variant = Set<members::variant>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `colours` field
        pub struct colours(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `variant` field
        pub struct variant(());
    }
}

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

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

impl<S: BosStr> ColourScheme<S> {
    /// Create a new builder for this type
    pub fn builder() -> ColourSchemeBuilder<colour_scheme_state::Empty, S> {
        ColourSchemeBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ColourSchemeBuilder<St, S>
where
    St: colour_scheme_state::State,
    St::Colours: colour_scheme_state::IsUnset,
{
    /// Set the `colours` field (required)
    pub fn colours(
        mut self,
        value: impl Into<ColourSchemeColours<S>>,
    ) -> ColourSchemeBuilder<colour_scheme_state::SetColours<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ColourSchemeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ColourSchemeBuilder<St, S>
where
    St: colour_scheme_state::State,
    St::Name: colour_scheme_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<S>,
    ) -> ColourSchemeBuilder<colour_scheme_state::SetName<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ColourSchemeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ColourSchemeBuilder<St, S>
where
    St: colour_scheme_state::State,
    St::Variant: colour_scheme_state::IsUnset,
{
    /// Set the `variant` field (required)
    pub fn variant(
        mut self,
        value: impl Into<S>,
    ) -> ColourSchemeBuilder<colour_scheme_state::SetVariant<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ColourSchemeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ColourSchemeBuilder<St, S>
where
    St: colour_scheme_state::State,
    St::Colours: colour_scheme_state::IsSet,
    St::Name: colour_scheme_state::IsSet,
    St::Variant: colour_scheme_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ColourScheme<S> {
        ColourScheme {
            colours: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            variant: 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>>,
    ) -> ColourScheme<S> {
        ColourScheme {
            colours: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            variant: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}