// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: science.alt.dataset.verificationMethod
//
// 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};
/// Automated test suite verification

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

/// Manual code review by a trusted party

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

/// Machine-checkable correctness proof (Coq, Lean, etc.)

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

/// Verification method identifier for lens verification records. Known values correspond to token definitions in this Lexicon. New verification methods can be added as tokens without breaking changes.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum VerificationMethod<S: BosStr = DefaultStr> {
    CodeReview,
    FormalProof,
    SignedHash,
    AutomatedTest,
    Other(S),
}

impl<S: BosStr> VerificationMethod<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::CodeReview => "codeReview",
            Self::FormalProof => "formalProof",
            Self::SignedHash => "signedHash",
            Self::AutomatedTest => "automatedTest",
            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() {
            "codeReview" => Self::CodeReview,
            "formalProof" => Self::FormalProof,
            "signedHash" => Self::SignedHash,
            "automatedTest" => Self::AutomatedTest,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for VerificationMethod<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 VerificationMethod<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 VerificationMethod<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = VerificationMethod<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            VerificationMethod::CodeReview => VerificationMethod::CodeReview,
            VerificationMethod::FormalProof => VerificationMethod::FormalProof,
            VerificationMethod::SignedHash => VerificationMethod::SignedHash,
            VerificationMethod::AutomatedTest => VerificationMethod::AutomatedTest,
            VerificationMethod::Other(v) => VerificationMethod::Other(v.into_static()),
        }
    }
}

/// Cryptographic signature over code hash at referenced commit

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