// @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.

pub mod list;
pub mod list_item;
pub mod rel;

use jacquard_common::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Item<'a> {
    #[serde(borrow)]
    pub r#ref: ItemRef<'a>,
    #[serde(borrow)]
    pub value: CowStr<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ItemRef<'a> {
    OpenLibrary,
    TmdbM,
    TmdbS,
    Other(CowStr<'a>),
}

impl<'a> ItemRef<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for ItemRef<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "open-library" => Self::OpenLibrary,
            "tmdb:m" => Self::TmdbM,
            "tmdb:s" => Self::TmdbS,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ItemRef<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "open-library" => Self::OpenLibrary,
            "tmdb:m" => Self::TmdbM,
            "tmdb:s" => Self::TmdbS,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for ItemRef<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for ItemRef<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for ItemRef<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for ItemRef<'_> {
    type Output = ItemRef<'static>;
    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<'a> LexiconSchema for Item<'a> {
    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()
    }
}