// @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;
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<'a> {
    CodeReview,
    FormalProof,
    SignedHash,
    AutomatedTest,
    Other(CowStr<'a>),
}

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

impl<'a> From<&'a str> for VerificationMethod<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "codeReview" => Self::CodeReview,
            "formalProof" => Self::FormalProof,
            "signedHash" => Self::SignedHash,
            "automatedTest" => Self::AutomatedTest,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for VerificationMethod<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "codeReview" => Self::CodeReview,
            "formalProof" => Self::FormalProof,
            "signedHash" => Self::SignedHash,
            "automatedTest" => Self::AutomatedTest,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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