// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: my.skylights.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

//! Generated bindings for the `my.skylights` Lexicon namespace/module.
pub mod list;
pub mod list_item;
pub mod rel;


#[allow(unused_imports)]
use alloc::collections::BTreeMap;
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};

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


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ItemRef<S: BosStr = DefaultStr> {
    OpenLibrary,
    TmdbM,
    TmdbS,
    Other(S),
}

impl<S: BosStr> ItemRef<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::OpenLibrary => "open-library",
            Self::TmdbM => "tmdb:m",
            Self::TmdbS => "tmdb:s",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "open-library" => Self::OpenLibrary,
            "tmdb:m" => Self::TmdbM,
            "tmdb:s" => Self::TmdbS,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for ItemRef<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for ItemRef<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for ItemRef<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ItemRef<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for ItemRef<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ItemRef<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ItemRef<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ItemRef::OpenLibrary => ItemRef::OpenLibrary,
            ItemRef::TmdbM => ItemRef::TmdbM,
            ItemRef::TmdbS => ItemRef::TmdbS,
            ItemRef::Other(v) => ItemRef::Other(v.into_static()),
        }
    }
}

impl<S: BosStr> LexiconSchema for Item<S> {
    fn nsid() -> &'static str {
        "my.skylights.defs"
    }
    fn def_name() -> &'static str {
        "item"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_my_skylights_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_my_skylights_defs() -> 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("my.skylights.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("item"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("ref"), SmolStr::new_static("value")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}