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

use jacquard_common::CowStr;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
/// JSON Schema Draft 7 format for sample type definitions. When schemaType is 'jsonSchema', the schema field must contain an object conforming to science.alt.dataset.schema#jsonSchemaFormat.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct JsonSchema;
impl core::fmt::Display for JsonSchema {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "jsonSchema")
    }
}

/// Schema type identifier for atdata sample definitions. Known values correspond to token definitions in this Lexicon. New schema types can be added as tokens without breaking changes.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SchemaType<'a> {
    JsonSchema,
    Other(CowStr<'a>),
}

impl<'a> SchemaType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::JsonSchema => "jsonSchema",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for SchemaType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "jsonSchema" => Self::JsonSchema,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for SchemaType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "jsonSchema" => Self::JsonSchema,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for SchemaType<'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 SchemaType<'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 jacquard_common::IntoStatic for SchemaType<'_> {
    type Output = SchemaType<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            SchemaType::JsonSchema => SchemaType::JsonSchema,
            SchemaType::Other(v) => SchemaType::Other(v.into_static()),
        }
    }
}