idiolect-records 0.8.0

Rust record types mirroring the dev.idiolect.* Lexicon family.
Documentation
// @generated by idiolect-codegen. do not edit.
// source: dev.idiolect.deliberationStatement

//! A participant utterance submitted to a `dev.idiolect.deliberation`. Statements are the units votes attach to; the deliberation itself is not voted on directly. Classification is an open-enum slug resolved against a community vocabulary, so communities that draw the line between `claim` and `proposal` differently can extend or remap without forking the lexicon.

#![allow(
    missing_docs,
    clippy::doc_markdown,
    clippy::struct_excessive_bools,
    clippy::derive_partial_eq_without_eq,
    clippy::large_enum_variant
)]
use serde::{Deserialize, Serialize};

/// A statement made within a deliberation. The text is the claim/proposal/dissent/clarification text; classification narrows the kind. Anonymous statements are typically authored under a service DID rather than the participant's personal repo; consumers needing provenance match on the repo DID rather than this record's content.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeliberationStatement {
    /// Whether the statement was submitted anonymously. Anonymous statements are typically authored on a designated service DID rather than the participant's personal repo; the repo DID is therefore the authoritative provenance signal.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub anonymous: Option<bool>,
    /// Open-enum slug naming the statement's argumentative role. Resolved against `classificationVocab` when present.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub classification: Option<DeliberationStatementClassification>,
    /// Vocabulary the `classification` slug resolves against. Omit to use the canonical idiolect default.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub classification_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
    pub created_at: idiolect_records::Datetime,
    /// Strong reference (AT-URI + CID) to the `dev.idiolect.deliberation` this statement participates in. Pinning by CID prevents a later deliberation revision from silently rescoping the statement.
    pub deliberation: crate::generated::dev::idiolect::defs::StrongRecordRef,
    /// Statement text. Brevity is conventional; long-form context belongs on the deliberation record.
    pub text: String,
}

impl crate::Record for DeliberationStatement {
    const NSID: &'static str = "dev.idiolect.deliberationStatement";
}

/// DeliberationStatementClassification. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DeliberationStatementClassification {
    Claim,
    Proposal,
    Dissent,
    Clarification,
    Question,
    /// Community-extended slug not present in the lexicon's
    /// `knownValues`. Resolves through the sibling
    /// `*Vocab` field on the containing record.
    Other(String),
}
impl DeliberationStatementClassification {
    /// Wire-form slug for this value. Known variants render
    /// kebab-case; the fallback variant passes through verbatim.
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::Claim => "claim",
            Self::Proposal => "proposal",
            Self::Dissent => "dissent",
            Self::Clarification => "clarification",
            Self::Question => "question",
            Self::Other(s) => s.as_str(),
        }
    }
    /// Whether this slug is subsumed by `ancestor` under the
    /// `subsumed_by` relation in the supplied vocab. Reflexive:
    /// every slug is subsumed by itself.
    #[must_use]
    pub fn is_subsumed_by(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        ancestor: &str,
    ) -> bool {
        vocab.is_subsumed_by(self.as_str(), ancestor)
    }
    /// Whether this slug satisfies a requirement of `target`
    /// under the named `relation` in the supplied vocab.
    /// Generalises `is_subsumed_by` to any directed relation
    /// (e.g. `stronger_than`, `provides_at_least`,
    /// `equivalent_to`). Reflexive: a slug satisfies itself.
    #[must_use]
    pub fn satisfies(
        &self,
        vocab: &idiolect_records::vocab::VocabGraph,
        relation: &str,
        target: &str,
    ) -> bool {
        if self.as_str() == target {
            return true;
        }
        vocab
            .walk_relation(self.as_str(), relation, false)
            .iter()
            .any(|n| n == target)
    }
    /// Translate this slug across vocabularies via
    /// `equivalent_to` edges. Returns the translated slug as
    /// a target enum value when a translation exists, `None`
    /// when no path is found (callers fall back to passing
    /// the slug through verbatim, which is wire-compatible).
    #[must_use]
    pub fn translate_to<T: From<String>>(
        &self,
        src_vocab_uri: &str,
        tgt_vocab_uri: &str,
        registry: &idiolect_records::vocab::VocabRegistry,
    ) -> Option<T> {
        registry
            .translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
            .map(T::from)
    }
}
impl From<String> for DeliberationStatementClassification {
    fn from(s: String) -> Self {
        match s.as_str() {
            "claim" => Self::Claim,
            "proposal" => Self::Proposal,
            "dissent" => Self::Dissent,
            "clarification" => Self::Clarification,
            "question" => Self::Question,
            _ => Self::Other(s),
        }
    }
}
impl From<&str> for DeliberationStatementClassification {
    fn from(s: &str) -> Self {
        match s {
            "claim" => Self::Claim,
            "proposal" => Self::Proposal,
            "dissent" => Self::Dissent,
            "clarification" => Self::Clarification,
            "question" => Self::Question,
            _ => Self::Other(s.to_owned()),
        }
    }
}
impl serde::Serialize for DeliberationStatementClassification {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}
impl<'de> serde::Deserialize<'de> for DeliberationStatementClassification {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = String::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}