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

use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
/// Arrow tensor format. Stores multi-dimensional arrays using Arrow's tensor IPC format. Versions maintained at https://json-schema.alt.science/atdata-arrow-tensor/{version}/

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

/// Array serialization format identifier for NDArray fields in sample schemas. Known values correspond to token definitions in this Lexicon. Each format has versioned specifications maintained by alt.science at canonical URLs.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ArrayFormat<S: BosStr = DefaultStr> {
    NdarrayBytes,
    SparseBytes,
    StructuredBytes,
    ArrowTensor,
    Safetensors,
    Other(S),
}

impl<S: BosStr> ArrayFormat<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::NdarrayBytes => "ndarrayBytes",
            Self::SparseBytes => "sparseBytes",
            Self::StructuredBytes => "structuredBytes",
            Self::ArrowTensor => "arrowTensor",
            Self::Safetensors => "safetensors",
            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() {
            "ndarrayBytes" => Self::NdarrayBytes,
            "sparseBytes" => Self::SparseBytes,
            "structuredBytes" => Self::StructuredBytes,
            "arrowTensor" => Self::ArrowTensor,
            "safetensors" => Self::Safetensors,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for ArrayFormat<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 ArrayFormat<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> jacquard_common::IntoStatic for ArrayFormat<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ArrayFormat<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ArrayFormat::NdarrayBytes => ArrayFormat::NdarrayBytes,
            ArrayFormat::SparseBytes => ArrayFormat::SparseBytes,
            ArrayFormat::StructuredBytes => ArrayFormat::StructuredBytes,
            ArrayFormat::ArrowTensor => ArrayFormat::ArrowTensor,
            ArrayFormat::Safetensors => ArrayFormat::Safetensors,
            ArrayFormat::Other(v) => ArrayFormat::Other(v.into_static()),
        }
    }
}

/// Numpy .npy binary format for NDArray serialization. Stores arrays with dtype and shape in binary header. Versions maintained at https://json-schema.alt.science/atdata-ndarray-bytes/{version}/

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

/// Safetensors format (HuggingFace). Stores ML tensors with safe, memory-mapped access. Versions maintained at https://json-schema.alt.science/atdata-safetensors/{version}/

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

/// Scipy sparse matrix format (CSR/CSC/COO). Stores sparse matrices with indices and data arrays. Versions maintained at https://json-schema.alt.science/atdata-sparse-bytes/{version}/

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

/// Numpy structured array format. Stores arrays with named, typed fields (compound dtypes). Versions maintained at https://json-schema.alt.science/atdata-structured-bytes/{version}/

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