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

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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{AtUri, Nsid};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon, 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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct CachePolicy<'a> {
    ///How frequently the underlying data changes
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub life: Option<CachePolicyLife<'a>>,
    ///Data dependencies for cache invalidation
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tags: Option<Vec<CachePolicyTagsItem<'a>>>,
}

/// How frequently the underlying data changes

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CachePolicyLife<'a> {
    Seconds,
    Minutes,
    Hours,
    Max,
    Other(CowStr<'a>),
}

impl<'a> CachePolicyLife<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for CachePolicyLife<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "seconds" => Self::Seconds,
            "minutes" => Self::Minutes,
            "hours" => Self::Hours,
            "max" => Self::Max,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for CachePolicyLife<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "seconds" => Self::Seconds,
            "minutes" => Self::Minutes,
            "hours" => Self::Hours,
            "max" => Self::Max,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

impl jacquard_common::IntoStatic for CachePolicyLife<'_> {
    type Output = CachePolicyLife<'static>;
    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")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum CachePolicyTagsItem<'a> {
    #[serde(rename = "at.inlay.defs#tagRecord")]
    TagRecord(Box<at_inlay::TagRecord<'a>>),
    #[serde(rename = "at.inlay.defs#tagLink")]
    TagLink(Box<at_inlay::TagLink<'a>>),
}

/// A renderable Inlay element.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Element<'a> {
    ///Stable key that identifies the component among its siblings.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub key: Option<CowStr<'a>>,
    ///Properties to pass to the component.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub props: Option<Data<'a>>,
    ///NSID of the component to render.
    #[serde(borrow)]
    pub r#type: Nsid<'a>,
}

/// Standard response from a component render call.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Response<'a> {
    ///Cache lifetime and invalidation tags
    #[serde(borrow)]
    pub cache: at_inlay::CachePolicy<'a>,
    ///Rendered element tree
    #[serde(borrow)]
    pub node: at_inlay::Element<'a>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TagLink<'a> {
    ///Collection NSID of the linking records. Omit for any collection.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub from: Option<Nsid<'a>>,
    ///Subject AT URI that is linked to
    #[serde(borrow)]
    pub subject: AtUri<'a>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TagRecord<'a> {
    ///AT URI at record, collection, or identity granularity
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ViaValtown<'a> {
    ///Val Town val UUID
    #[serde(borrow)]
    pub val_id: CowStr<'a>,
}

impl<'a> LexiconSchema for CachePolicy<'a> {
    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<'a> LexiconSchema for Element<'a> {
    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<'a> LexiconSchema for Response<'a> {
    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<'a> LexiconSchema for TagLink<'a> {
    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<'a> LexiconSchema for TagRecord<'a> {
    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<'a> LexiconSchema for ViaValtown<'a> {
    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<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>;
    }
    /// 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<'a, S: element_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<Data<'a>>, Option<Nsid<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: element_state::State> ElementBuilder<'a, S> {
    /// Set the `props` field (optional)
    pub fn props(mut self, value: impl Into<Option<Data<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<'a, S> ElementBuilder<'a, S>
where
    S: element_state::State,
    S::Type: element_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Element<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Element<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCache<S> {}
    impl<S: State> State for SetCache<S> {
        type Cache = Set<members::cache>;
        type Node = S::Node;
    }
    ///State transition - sets the `node` field to Set
    pub struct SetNode<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNode<S> {}
    impl<S: State> State for SetNode<S> {
        type Cache = S::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<'a, S: response_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<at_inlay::CachePolicy<'a>>, Option<at_inlay::Element<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> ResponseBuilder<'a, S>
where
    S: response_state::State,
    S::Cache: response_state::IsSet,
    S::Node: response_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Response<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Response<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubject<S> {}
    impl<S: State> State for SetSubject<S> {
        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<'a, S: tag_link_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Nsid<'a>>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> TagLinkBuilder<'a, S>
where
    S: tag_link_state::State,
    S::Subject: tag_link_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> TagLink<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> TagLink<'a> {
        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<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 TagRecordBuilder<'a, S: tag_record_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AtUri<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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