// @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;
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<'a> {
    NdarrayBytes,
    SparseBytes,
    StructuredBytes,
    ArrowTensor,
    Safetensors,
    Other(CowStr<'a>),
}

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

impl<'a> From<&'a str> for ArrayFormat<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "ndarrayBytes" => Self::NdarrayBytes,
            "sparseBytes" => Self::SparseBytes,
            "structuredBytes" => Self::StructuredBytes,
            "arrowTensor" => Self::ArrowTensor,
            "safetensors" => Self::Safetensors,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ArrayFormat<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "ndarrayBytes" => Self::NdarrayBytes,
            "sparseBytes" => Self::SparseBytes,
            "structuredBytes" => Self::StructuredBytes,
            "arrowTensor" => Self::ArrowTensor,
            "safetensors" => Self::Safetensors,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for ArrayFormat<'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 ArrayFormat<'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 ArrayFormat<'_> {
    type Output = ArrayFormat<'static>;
    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")
    }
}