// @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.

//! Generated bindings for the `org.impactindexer.review` Lexicon namespace/module.
pub mod comment;
pub mod like;


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

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SubjectRef<S: BosStr = DefaultStr> {
    ///Optional CID for record subjects to pin to a specific version.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<S>,
    ///The type of subject.
    pub r#type: review::SubjectType<S>,
    ///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).
    pub uri: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// The type of subject being reviewed.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SubjectType<S: BosStr = DefaultStr> {
    Record,
    User,
    Pds,
    Lexicon,
    Other(S),
}

impl<S: BosStr> SubjectType<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "record" => Self::Record,
            "user" => Self::User,
            "pds" => Self::Pds,
            "lexicon" => Self::Lexicon,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for SubjectType<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 SubjectType<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 SubjectType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = SubjectType<S::Output>;
    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<S: BosStr> LexiconSchema for SubjectRef<S> {
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetType<St> {}
    impl<St: State> State for SetType<St> {
        type Type = Set<members::r#type>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Type = St::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<St: subject_ref_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<review::SubjectType<S>>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

impl SubjectRef<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> SubjectRefBuilder<subject_ref_state::Empty, DefaultStr> {
        SubjectRefBuilder::new()
    }
}

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

impl SubjectRefBuilder<subject_ref_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        SubjectRefBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _type: PhantomData,
        }
    }
}

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

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

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

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

impl<St, S: BosStr> SubjectRefBuilder<St, S>
where
    St: subject_ref_state::State,
    St::Type: subject_ref_state::IsSet,
    St::Uri: subject_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SubjectRef<S> {
        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<SmolStr, Data<S>>,
    ) -> SubjectRef<S> {
        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()
    }
}