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

//! Generated bindings for the `zone.stratos` Lexicon namespace/module.
pub mod actor;
pub mod boundary;
pub mod enrollment;
pub mod feed;
pub mod identity;
pub mod repo;
pub mod sync;


#[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::string::{Did, AtUri, Cid};
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::zone_stratos;
/// Indicates this record requires hydration from an external service. The stub record on the PDS contains minimal data; full content is fetched from the service endpoint.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Source<S: BosStr = DefaultStr> {
    ///DID of the hydration service, optionally with fragment identifying the service entry (e.g., 'did:plc:abc123#atproto_pns').
    pub service: Did<S>,
    ///Reference to the full record at the hydration service.
    pub subject: zone_stratos::SubjectRef<S>,
    ///Indicates when hydration is needed. 'authenticated' means full content requires viewer authentication.
    pub vary: SourceVary<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Indicates when hydration is needed. 'authenticated' means full content requires viewer authentication.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SourceVary<S: BosStr = DefaultStr> {
    Authenticated,
    Unauthenticated,
    Other(S),
}

impl<S: BosStr> SourceVary<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Authenticated => "authenticated",
            Self::Unauthenticated => "unauthenticated",
            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() {
            "authenticated" => Self::Authenticated,
            "unauthenticated" => Self::Unauthenticated,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for SourceVary<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 SourceVary<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 + Default> Default for SourceVary<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for SourceVary<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = SourceVary<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            SourceVary::Authenticated => SourceVary::Authenticated,
            SourceVary::Unauthenticated => SourceVary::Unauthenticated,
            SourceVary::Other(v) => SourceVary::Other(v.into_static()),
        }
    }
}

/// A strong reference to a record, including its content hash for verification.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SubjectRef<S: BosStr = DefaultStr> {
    ///CID of the full record content for integrity verification.
    pub cid: Cid<S>,
    ///AT-URI of the record at the hydration service.
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Source<S> {
    fn nsid() -> &'static str {
        "zone.stratos.defs"
    }
    fn def_name() -> &'static str {
        "source"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_zone_stratos_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.vary;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("vary"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for SubjectRef<S> {
    fn nsid() -> &'static str {
        "zone.stratos.defs"
    }
    fn def_name() -> &'static str {
        "subjectRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_zone_stratos_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod source_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 Service;
        type Subject;
        type Vary;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Service = Unset;
        type Subject = Unset;
        type Vary = Unset;
    }
    ///State transition - sets the `service` field to Set
    pub struct SetService<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetService<St> {}
    impl<St: State> State for SetService<St> {
        type Service = Set<members::service>;
        type Subject = St::Subject;
        type Vary = St::Vary;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type Service = St::Service;
        type Subject = Set<members::subject>;
        type Vary = St::Vary;
    }
    ///State transition - sets the `vary` field to Set
    pub struct SetVary<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetVary<St> {}
    impl<St: State> State for SetVary<St> {
        type Service = St::Service;
        type Subject = St::Subject;
        type Vary = Set<members::vary>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `service` field
        pub struct service(());
        ///Marker type for the `subject` field
        pub struct subject(());
        ///Marker type for the `vary` field
        pub struct vary(());
    }
}

/// Builder for constructing an instance of this type.
pub struct SourceBuilder<St: source_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Did<S>>,
        Option<zone_stratos::SubjectRef<S>>,
        Option<SourceVary<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Source<S> {
    /// Create a new builder for this type
    pub fn builder() -> SourceBuilder<source_state::Empty, S> {
        SourceBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SourceBuilder<St, S>
where
    St: source_state::State,
    St::Service: source_state::IsUnset,
{
    /// Set the `service` field (required)
    pub fn service(
        mut self,
        value: impl Into<Did<S>>,
    ) -> SourceBuilder<source_state::SetService<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SourceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SourceBuilder<St, S>
where
    St: source_state::State,
    St::Subject: source_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<zone_stratos::SubjectRef<S>>,
    ) -> SourceBuilder<source_state::SetSubject<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SourceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SourceBuilder<St, S>
where
    St: source_state::State,
    St::Vary: source_state::IsUnset,
{
    /// Set the `vary` field (required)
    pub fn vary(
        mut self,
        value: impl Into<SourceVary<S>>,
    ) -> SourceBuilder<source_state::SetVary<St>, S> {
        self._fields.2 = Option::Some(value.into());
        SourceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SourceBuilder<St, S>
where
    St: source_state::State,
    St::Service: source_state::IsSet,
    St::Subject: source_state::IsSet,
    St::Vary: source_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Source<S> {
        Source {
            service: self._fields.0.unwrap(),
            subject: self._fields.1.unwrap(),
            vary: 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>>) -> Source<S> {
        Source {
            service: self._fields.0.unwrap(),
            subject: self._fields.1.unwrap(),
            vary: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_zone_stratos_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("zone.stratos.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("source"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Indicates this record requires hydration from an external service. The stub record on the PDS contains minimal data; full content is fetched from the service endpoint.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("vary"), SmolStr::new_static("subject"),
                            SmolStr::new_static("service")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("service"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "DID of the hydration service, optionally with fragment identifying the service entry (e.g., 'did:plc:abc123#atproto_pns').",
                                    ),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("subject"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#subjectRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("vary"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Indicates when hydration is needed. 'authenticated' means full content requires viewer authentication.",
                                    ),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("subjectRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A strong reference to a record, including its content hash for verification.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("cid")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "CID of the full record content for integrity verification.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "AT-URI of the record at the hydration service.",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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 Cid;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCid<St> {}
    impl<St: State> State for SetCid<St> {
        type Cid = Set<members::cid>;
        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 Cid = St::Cid;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///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<Cid<S>>, Option<AtUri<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),
            _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),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SubjectRefBuilder<St, S>
where
    St: subject_ref_state::State,
    St::Cid: subject_ref_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> SubjectRefBuilder<subject_ref_state::SetCid<St>, S> {
        self._fields.0 = 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<AtUri<S>>,
    ) -> SubjectRefBuilder<subject_ref_state::SetUri<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::Cid: 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.unwrap(),
            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<SmolStr, Data<S>>,
    ) -> SubjectRef<S> {
        SubjectRef {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}