// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: net.asadaame5121.at-circle.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod banner;
pub mod block;
pub mod member;
pub mod request;
pub mod ring;


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

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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{AtUri, Cid};
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};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RingRef<'a> {
    ///Optional CID for strong reference
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    ///AT-URI of the Ring
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}

impl<'a> LexiconSchema for RingRef<'a> {
    fn nsid() -> &'static str {
        "net.asadaame5121.at-circle.defs"
    }
    fn def_name() -> &'static str {
        "ringRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_asadaame5121_at_circle_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.cid {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("cid"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.uri;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("uri"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod ring_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 Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
    }
    ///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 Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type
pub struct RingRefBuilder<'a, S: ring_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Cid<'a>>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> RingRef<'a> {
    /// Create a new builder for this type
    pub fn new() -> RingRefBuilder<'a, ring_ref_state::Empty> {
        RingRefBuilder::new()
    }
}

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

impl<'a, S: ring_ref_state::State> RingRefBuilder<'a, S> {
    /// Set the `cid` field (optional)
    pub fn cid(mut self, value: impl Into<Option<Cid<'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<Cid<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<'a, S> RingRefBuilder<'a, S>
where
    S: ring_ref_state::State,
    S::Uri: ring_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RingRef<'a> {
        RingRef {
            cid: self._fields.0,
            uri: self._fields.1.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>,
        >,
    ) -> RingRef<'a> {
        RingRef {
            cid: self._fields.0,
            uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_net_asadaame5121_at_circle_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("net.asadaame5121.at-circle.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("ringRef"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("uri")]),
                    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 strong reference"),
                                ),
                                format: Some(LexStringFormat::Cid),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("AT-URI of the Ring")),
                                format: Some(LexStringFormat::AtUri),
                                max_length: Some(2000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}