jacquard-api 0.11.0

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.impactindexer.review.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod comment;
pub mod like;


#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::org_impactindexer::review;
/// Reference to the subject being reviewed.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SubjectRef<'a> {
    ///Optional CID for record subjects to pin to a specific version.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<CowStr<'a>>,
    ///The type of subject.
    #[serde(borrow)]
    pub r#type: review::SubjectType<'a>,
    ///The subject identifier. For records: AT-URI (at://did/collection/rkey). For users: DID (did:plc:xxx). For PDSes: hostname (example.com). For lexicons: NSID (app.bsky.feed.post).
    #[serde(borrow)]
    pub uri: CowStr<'a>,
}

/// The type of subject being reviewed.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SubjectType<'a> {
    Record,
    User,
    Pds,
    Lexicon,
    Other(CowStr<'a>),
}

impl<'a> SubjectType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Record => "record",
            Self::User => "user",
            Self::Pds => "pds",
            Self::Lexicon => "lexicon",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for SubjectType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "record" => Self::Record,
            "user" => Self::User,
            "pds" => Self::Pds,
            "lexicon" => Self::Lexicon,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for SubjectType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "record" => Self::Record,
            "user" => Self::User,
            "pds" => Self::Pds,
            "lexicon" => Self::Lexicon,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for SubjectType<'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 SubjectType<'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 SubjectType<'_> {
    type Output = SubjectType<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            SubjectType::Record => SubjectType::Record,
            SubjectType::User => SubjectType::User,
            SubjectType::Pds => SubjectType::Pds,
            SubjectType::Lexicon => SubjectType::Lexicon,
            SubjectType::Other(v) => SubjectType::Other(v.into_static()),
        }
    }
}

impl<'a> LexiconSchema for SubjectRef<'a> {
    fn nsid() -> &'static str {
        "org.impactindexer.review.defs"
    }
    fn def_name() -> &'static str {
        "subjectRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_impactindexer_review_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.cid {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("cid"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.uri;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 8192usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("uri"),
                    max: 8192usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod subject_ref_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Type;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Type = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `type` field to Set
    pub struct SetType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetType<S> {}
    impl<S: State> State for SetType<S> {
        type Type = Set<members::r#type>;
        type Uri = S::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Type = S::Type;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `type` field
        pub struct r#type(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type
pub struct SubjectRefBuilder<'a, S: subject_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<review::SubjectType<'a>>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> SubjectRef<'a> {
    /// Create a new builder for this type
    pub fn new() -> SubjectRefBuilder<'a, subject_ref_state::Empty> {
        SubjectRefBuilder::new()
    }
}

impl<'a> SubjectRefBuilder<'a, subject_ref_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        SubjectRefBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: subject_ref_state::State> SubjectRefBuilder<'a, S> {
    /// Set the `cid` field (optional)
    pub fn cid(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `cid` field to an Option value (optional)
    pub fn maybe_cid(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> SubjectRefBuilder<'a, S>
where
    S: subject_ref_state::State,
    S::Type: subject_ref_state::IsUnset,
{
    /// Set the `type` field (required)
    pub fn r#type(
        mut self,
        value: impl Into<review::SubjectType<'a>>,
    ) -> SubjectRefBuilder<'a, subject_ref_state::SetType<S>> {
        self._fields.1 = Option::Some(value.into());
        SubjectRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SubjectRefBuilder<'a, S>
where
    S: subject_ref_state::State,
    S::Uri: subject_ref_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> SubjectRefBuilder<'a, subject_ref_state::SetUri<S>> {
        self._fields.2 = Option::Some(value.into());
        SubjectRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SubjectRefBuilder<'a, S>
where
    S: subject_ref_state::State,
    S::Type: subject_ref_state::IsSet,
    S::Uri: subject_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SubjectRef<'a> {
        SubjectRef {
            cid: self._fields.0,
            r#type: self._fields.1.unwrap(),
            uri: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> SubjectRef<'a> {
        SubjectRef {
            cid: self._fields.0,
            r#type: self._fields.1.unwrap(),
            uri: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_impactindexer_review_defs() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("org.impactindexer.review.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("subjectRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Reference to the subject being reviewed."),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("type")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional CID for record subjects to pin to a specific version.",
                                    ),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#subjectType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The subject identifier. For records: AT-URI (at://did/collection/rkey). For users: DID (did:plc:xxx). For PDSes: hostname (example.com). For lexicons: NSID (app.bsky.feed.post).",
                                    ),
                                ),
                                max_length: Some(8192usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("subjectType"),
                LexUserType::String(LexString {
                    description: Some(
                        CowStr::new_static("The type of subject being reviewed."),
                    ),
                    max_length: Some(32usize),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}