// @generated by idiolect-codegen. do not edit.
// source: dev.idiolect.deliberationVote
//! A stance taken on a `dev.idiolect.deliberationStatement`. Stance is an open-enum slug resolved against a community-published vote-stance vocabulary. Acorn-style three-way votes (agree/pass/disagree) are the canonical default; richer vocabularies (conditional-agree, abstain-with-reason, ranked preference) are expressible by referencing a different vocab. Optional `weight` and `rationale` capture additional signal that observers and orchestrators can fold into outcomes; consumers that don't need them simply ignore them.
#![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 vote on a deliberation statement. The subject pins the exact statement revision via CID so a later edit cannot silently change what was voted on.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeliberationVote {
pub created_at: idiolect_records::Datetime,
/// Optional narrative reason for the stance. Not consumed by tally folds; useful for orchestrator surfaces that show vote provenance.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rationale: Option<String>,
/// Open-enum slug naming the stance. Resolved against `stanceVocab` when present, otherwise against the canonical idiolect vote-stance vocabulary.
pub stance: DeliberationVoteStance,
/// Vocabulary the `stance` slug resolves against. Omit to use the canonical idiolect default.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub stance_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
/// Strong reference (AT-URI + CID) to the `dev.idiolect.deliberationStatement` being voted on.
pub subject: crate::generated::dev::idiolect::defs::StrongRecordRef,
/// Optional ranking signal scaled by 1000 for the 0.0-1.0 range. Convention follows `pub.chive.graph.edge#weight`. Consumers that aggregate votes uniformly may ignore this; ranked or weighted aggregations consume it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub weight: Option<i64>,
}
impl crate::Record for DeliberationVote {
const NSID: &'static str = "dev.idiolect.deliberationVote";
}
/// DeliberationVoteStance. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DeliberationVoteStance {
Agree,
Pass,
Disagree,
/// Community-extended slug not present in the lexicon's
/// `knownValues`. Resolves through the sibling
/// `*Vocab` field on the containing record.
Other(String),
}
impl DeliberationVoteStance {
/// 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::Agree => "agree",
Self::Pass => "pass",
Self::Disagree => "disagree",
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 DeliberationVoteStance {
fn from(s: String) -> Self {
match s.as_str() {
"agree" => Self::Agree,
"pass" => Self::Pass,
"disagree" => Self::Disagree,
_ => Self::Other(s),
}
}
}
impl From<&str> for DeliberationVoteStance {
fn from(s: &str) -> Self {
match s {
"agree" => Self::Agree,
"pass" => Self::Pass,
"disagree" => Self::Disagree,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for DeliberationVoteStance {
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 DeliberationVoteStance {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}