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

//! Generated bindings for the `at.inlay` Lexicon namespace/module.
pub mod binding;
pub mod component;
pub mod fragment;
pub mod loading;
pub mod maybe;
pub mod missing;
pub mod pack;
pub mod placeholder;
pub mod slot;
pub mod throw;


#[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::{AtUri, Nsid};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
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::at_inlay;
/// Cache lifetime and invalidation tags returned by XRPC components.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CachePolicy<S: BosStr = DefaultStr> {
    ///How frequently the underlying data changes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub life: Option<CachePolicyLife<S>>,
    ///Data dependencies for cache invalidation
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<CachePolicyTagsItem<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// How frequently the underlying data changes

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CachePolicyLife<S: BosStr = DefaultStr> {
    Seconds,
    Minutes,
    Hours,
    Max,
    Other(S),
}

impl<S: BosStr> CachePolicyLife<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Seconds => "seconds",
            Self::Minutes => "minutes",
            Self::Hours => "hours",
            Self::Max => "max",
            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() {
            "seconds" => Self::Seconds,
            "minutes" => Self::Minutes,
            "hours" => Self::Hours,
            "max" => Self::Max,
            _ => Self::Other(s),
        }
    }
}

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for CachePolicyLife<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = CachePolicyLife<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            CachePolicyLife::Seconds => CachePolicyLife::Seconds,
            CachePolicyLife::Minutes => CachePolicyLife::Minutes,
            CachePolicyLife::Hours => CachePolicyLife::Hours,
            CachePolicyLife::Max => CachePolicyLife::Max,
            CachePolicyLife::Other(v) => CachePolicyLife::Other(v.into_static()),
        }
    }
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CachePolicyTagsItem<S: BosStr = DefaultStr> {
    #[serde(rename = "at.inlay.defs#tagRecord")]
    TagRecord(Box<at_inlay::TagRecord<S>>),
    #[serde(rename = "at.inlay.defs#tagLink")]
    TagLink(Box<at_inlay::TagLink<S>>),
}

/// A renderable Inlay element.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Element<S: BosStr = DefaultStr> {
    ///Stable key that identifies the component among its siblings.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key: Option<S>,
    ///Properties to pass to the component.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub props: Option<Data<S>>,
    ///NSID of the component to render.
    pub r#type: Nsid<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Standard response from a component render call.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Response<S: BosStr = DefaultStr> {
    ///Cache lifetime and invalidation tags
    pub cache: at_inlay::CachePolicy<S>,
    ///Rendered element tree
    pub node: at_inlay::Element<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Cache tag: depend on backlink relationships to a subject.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct TagLink<S: BosStr = DefaultStr> {
    ///Collection NSID of the linking records. Omit for any collection.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<Nsid<S>>,
    ///Subject AT URI that is linked to
    pub subject: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Cache tag: depend on a specific record, collection, or identity.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct TagRecord<S: BosStr = DefaultStr> {
    ///AT URI at record, collection, or identity granularity
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ViaValtown<S: BosStr = DefaultStr> {
    ///Val Town val UUID
    pub val_id: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for CachePolicy<S> {
    fn nsid() -> &'static str {
        "at.inlay.defs"
    }
    fn def_name() -> &'static str {
        "cachePolicy"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_at_inlay_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.life {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("life"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Element<S> {
    fn nsid() -> &'static str {
        "at.inlay.defs"
    }
    fn def_name() -> &'static str {
        "element"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_at_inlay_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.key {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("key"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Response<S> {
    fn nsid() -> &'static str {
        "at.inlay.defs"
    }
    fn def_name() -> &'static str {
        "response"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_at_inlay_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for TagLink<S> {
    fn nsid() -> &'static str {
        "at.inlay.defs"
    }
    fn def_name() -> &'static str {
        "tagLink"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_at_inlay_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for TagRecord<S> {
    fn nsid() -> &'static str {
        "at.inlay.defs"
    }
    fn def_name() -> &'static str {
        "tagRecord"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_at_inlay_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

fn lexicon_doc_at_inlay_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("at.inlay.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("cachePolicy"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Cache lifetime and invalidation tags returned by XRPC components.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("life"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "How frequently the underlying data changes",
                                    ),
                                ),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("tags"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Data dependencies for cache invalidation",
                                    ),
                                ),
                                items: LexArrayItem::Union(LexRefUnion {
                                    refs: vec![
                                        CowStr::new_static("#tagRecord"),
                                        CowStr::new_static("#tagLink")
                                    ],
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("element"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A renderable Inlay element.")),
                    required: Some(vec![SmolStr::new_static("type")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("key"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Stable key that identifies the component among its siblings.",
                                    ),
                                ),
                                max_length: Some(256usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("props"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("NSID of the component to render."),
                                ),
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("response"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Standard response from a component render call.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("node"), SmolStr::new_static("cache")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cache"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#cachePolicy"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("node"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#element"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("tagLink"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Cache tag: depend on backlink relationships to a subject.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("subject")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("from"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Collection NSID of the linking records. Omit for any collection.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("subject"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Subject AT URI that is linked to"),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("tagRecord"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Cache tag: depend on a specific record, collection, or identity.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("uri")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "AT URI at record, collection, or identity granularity",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viaValtown"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("valId")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("valId"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Val Town val UUID")),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type.
pub struct ElementBuilder<St: element_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<Data<S>>, Option<Nsid<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Element<S> {
    /// Create a new builder for this type
    pub fn builder() -> ElementBuilder<element_state::Empty, S> {
        ElementBuilder::builder()
    }
}

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

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

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

impl<St: element_state::State, S: BosStr> ElementBuilder<St, S> {
    /// Set the `props` field (optional)
    pub fn props(mut self, value: impl Into<Option<Data<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `props` field to an Option value (optional)
    pub fn maybe_props(mut self, value: Option<Data<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<St, S: BosStr> ElementBuilder<St, S>
where
    St: element_state::State,
    St::Type: element_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Element<S> {
        Element {
            key: self._fields.0,
            props: self._fields.1,
            r#type: 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>>) -> Element<S> {
        Element {
            key: self._fields.0,
            props: self._fields.1,
            r#type: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod response_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 Cache;
        type Node;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cache = Unset;
        type Node = Unset;
    }
    ///State transition - sets the `cache` field to Set
    pub struct SetCache<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCache<St> {}
    impl<St: State> State for SetCache<St> {
        type Cache = Set<members::cache>;
        type Node = St::Node;
    }
    ///State transition - sets the `node` field to Set
    pub struct SetNode<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetNode<St> {}
    impl<St: State> State for SetNode<St> {
        type Cache = St::Cache;
        type Node = Set<members::node>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cache` field
        pub struct cache(());
        ///Marker type for the `node` field
        pub struct node(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ResponseBuilder<St: response_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<at_inlay::CachePolicy<S>>, Option<at_inlay::Element<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Response<S> {
    /// Create a new builder for this type
    pub fn builder() -> ResponseBuilder<response_state::Empty, S> {
        ResponseBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ResponseBuilder<St, S>
where
    St: response_state::State,
    St::Cache: response_state::IsUnset,
{
    /// Set the `cache` field (required)
    pub fn cache(
        mut self,
        value: impl Into<at_inlay::CachePolicy<S>>,
    ) -> ResponseBuilder<response_state::SetCache<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ResponseBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ResponseBuilder<St, S>
where
    St: response_state::State,
    St::Node: response_state::IsUnset,
{
    /// Set the `node` field (required)
    pub fn node(
        mut self,
        value: impl Into<at_inlay::Element<S>>,
    ) -> ResponseBuilder<response_state::SetNode<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ResponseBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ResponseBuilder<St, S>
where
    St: response_state::State,
    St::Cache: response_state::IsSet,
    St::Node: response_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Response<S> {
        Response {
            cache: self._fields.0.unwrap(),
            node: 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>>) -> Response<S> {
        Response {
            cache: self._fields.0.unwrap(),
            node: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

/// Builder for constructing an instance of this type.
pub struct TagLinkBuilder<St: tag_link_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Nsid<S>>, Option<AtUri<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> TagLink<S> {
    /// Create a new builder for this type
    pub fn builder() -> TagLinkBuilder<tag_link_state::Empty, S> {
        TagLinkBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> TagLinkBuilder<St, S>
where
    St: tag_link_state::State,
    St::Subject: tag_link_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TagLink<S> {
        TagLink {
            from: self._fields.0,
            subject: 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>>) -> TagLink<S> {
        TagLink {
            from: self._fields.0,
            subject: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod tag_record_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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        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 TagRecordBuilder<St: tag_record_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<AtUri<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> TagRecord<S> {
    /// Create a new builder for this type
    pub fn builder() -> TagRecordBuilder<tag_record_state::Empty, S> {
        TagRecordBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> TagRecordBuilder<St, S>
where
    St: tag_record_state::State,
    St::Uri: tag_record_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TagRecord<S> {
        TagRecord {
            uri: self._fields.0.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>>,
    ) -> TagRecord<S> {
        TagRecord {
            uri: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}