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

#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
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};
/// A stage role vs a performance of that role. The Opening of the Mouth was performed on a type of figure — the Role is the type. The Character instance is the specific statue that gets its mouth opened.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "world.ptah.temp.role",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Role<S: BosStr = DefaultStr> {
    ///Permanent link to the role's creator. Provenance travels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub authorship_record: Option<Did<S>>,
    ///The AT URI of the single Character record designated as the authoritative expression of this role. When present, this is the canonical instance.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub canonical_character_reference: Option<AtUri<S>>,
    ///Governs how the canonicalCharacterReference behaves over time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub canonical_reference_policy: Option<RoleCanonicalReferencePolicy<S>>,
    ///The canonical standing of this role within its world.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub canonical_status: Option<RoleCanonicalStatus<S>>,
    ///Timestamp of role creation.
    pub created_at: Datetime,
    ///Who defined this role in the protocol.
    pub creator_did: Did<S>,
    ///What this role is in the world's context — its narrative function, its archetypal weight.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///How instances of this role are governed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub instance_policy: Option<RoleInstancePolicy<S>>,
    ///What this role is called.
    pub name: S,
    ///If sourceType is publicDomain, the specific source material.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_reference: Option<S>,
    ///The intellectual property origin of this role.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_type: Option<RoleSourceType<S>>,
    ///The AT URI of the world record this role exists in.
    pub world_reference: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Governs how the canonicalCharacterReference behaves over time.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RoleCanonicalReferencePolicy<S: BosStr = DefaultStr> {
    Fixed,
    Updatable,
    Community,
    Other(S),
}

impl<S: BosStr> RoleCanonicalReferencePolicy<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Fixed => "fixed",
            Self::Updatable => "updatable",
            Self::Community => "community",
            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() {
            "fixed" => Self::Fixed,
            "updatable" => Self::Updatable,
            "community" => Self::Community,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

/// The canonical standing of this role within its world.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RoleCanonicalStatus<S: BosStr = DefaultStr> {
    CanonicalStatusOfficial,
    CanonicalStatusCommunity,
    CanonicalStatusApocryphal,
    Other(S),
}

impl<S: BosStr> RoleCanonicalStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::CanonicalStatusOfficial => {
                "world.ptah.temp.defs#canonicalStatusOfficial"
            }
            Self::CanonicalStatusCommunity => {
                "world.ptah.temp.defs#canonicalStatusCommunity"
            }
            Self::CanonicalStatusApocryphal => {
                "world.ptah.temp.defs#canonicalStatusApocryphal"
            }
            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() {
            "world.ptah.temp.defs#canonicalStatusOfficial" => {
                Self::CanonicalStatusOfficial
            }
            "world.ptah.temp.defs#canonicalStatusCommunity" => {
                Self::CanonicalStatusCommunity
            }
            "world.ptah.temp.defs#canonicalStatusApocryphal" => {
                Self::CanonicalStatusApocryphal
            }
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

/// How instances of this role are governed.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RoleInstancePolicy<S: BosStr = DefaultStr> {
    OpenInstance,
    ApprovedInstance,
    SingleInstance,
    Other(S),
}

impl<S: BosStr> RoleInstancePolicy<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::OpenInstance => "openInstance",
            Self::ApprovedInstance => "approvedInstance",
            Self::SingleInstance => "singleInstance",
            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() {
            "openInstance" => Self::OpenInstance,
            "approvedInstance" => Self::ApprovedInstance,
            "singleInstance" => Self::SingleInstance,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

/// The intellectual property origin of this role.

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

impl<S: BosStr> RoleSourceType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::SourceTypeOriginalIp => "world.ptah.temp.defs#sourceTypeOriginalIP",
            Self::SourceTypePublicDomain => "world.ptah.temp.defs#sourceTypePublicDomain",
            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() {
            "world.ptah.temp.defs#sourceTypeOriginalIP" => Self::SourceTypeOriginalIp,
            "world.ptah.temp.defs#sourceTypePublicDomain" => Self::SourceTypePublicDomain,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RoleGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Role<S>,
}

impl<S: BosStr> Role<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, RoleRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct RoleRecord;
impl XrpcResp for RoleRecord {
    const NSID: &'static str = "world.ptah.temp.role";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = RoleGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<RoleGetRecordOutput<S>> for Role<S> {
    fn from(output: RoleGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Role<S> {
    const NSID: &'static str = "world.ptah.temp.role";
    type Record = RoleRecord;
}

impl Collection for RoleRecord {
    const NSID: &'static str = "world.ptah.temp.role";
    type Record = RoleRecord;
}

impl<S: BosStr> LexiconSchema for Role<S> {
    fn nsid() -> &'static str {
        "world.ptah.temp.role"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_world_ptah_temp_role()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10240usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 10240usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.description {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1024usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("description"),
                        max: 1024usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("name"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.source_reference {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10240usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("source_reference"),
                    max: 10240usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.source_reference {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1024usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("source_reference"),
                        max: 1024usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod role_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 CreatedAt;
        type CreatorDid;
        type Name;
        type WorldReference;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type CreatorDid = Unset;
        type Name = Unset;
        type WorldReference = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type CreatorDid = St::CreatorDid;
        type Name = St::Name;
        type WorldReference = St::WorldReference;
    }
    ///State transition - sets the `creator_did` field to Set
    pub struct SetCreatorDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatorDid<St> {}
    impl<St: State> State for SetCreatorDid<St> {
        type CreatedAt = St::CreatedAt;
        type CreatorDid = Set<members::creator_did>;
        type Name = St::Name;
        type WorldReference = St::WorldReference;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type CreatedAt = St::CreatedAt;
        type CreatorDid = St::CreatorDid;
        type Name = Set<members::name>;
        type WorldReference = St::WorldReference;
    }
    ///State transition - sets the `world_reference` field to Set
    pub struct SetWorldReference<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetWorldReference<St> {}
    impl<St: State> State for SetWorldReference<St> {
        type CreatedAt = St::CreatedAt;
        type CreatorDid = St::CreatorDid;
        type Name = St::Name;
        type WorldReference = Set<members::world_reference>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `creator_did` field
        pub struct creator_did(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `world_reference` field
        pub struct world_reference(());
    }
}

/// Builder for constructing an instance of this type.
pub struct RoleBuilder<St: role_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Did<S>>,
        Option<AtUri<S>>,
        Option<RoleCanonicalReferencePolicy<S>>,
        Option<RoleCanonicalStatus<S>>,
        Option<Datetime>,
        Option<Did<S>>,
        Option<S>,
        Option<RoleInstancePolicy<S>>,
        Option<S>,
        Option<S>,
        Option<RoleSourceType<S>>,
        Option<AtUri<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Role<S> {
    /// Create a new builder for this type
    pub fn builder() -> RoleBuilder<role_state::Empty, S> {
        RoleBuilder::builder()
    }
}

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

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

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `authorshipRecord` field (optional)
    pub fn authorship_record(mut self, value: impl Into<Option<Did<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `authorshipRecord` field to an Option value (optional)
    pub fn maybe_authorship_record(mut self, value: Option<Did<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `canonicalCharacterReference` field (optional)
    pub fn canonical_character_reference(
        mut self,
        value: impl Into<Option<AtUri<S>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `canonicalCharacterReference` field to an Option value (optional)
    pub fn maybe_canonical_character_reference(
        mut self,
        value: Option<AtUri<S>>,
    ) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `canonicalReferencePolicy` field (optional)
    pub fn canonical_reference_policy(
        mut self,
        value: impl Into<Option<RoleCanonicalReferencePolicy<S>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `canonicalReferencePolicy` field to an Option value (optional)
    pub fn maybe_canonical_reference_policy(
        mut self,
        value: Option<RoleCanonicalReferencePolicy<S>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `canonicalStatus` field (optional)
    pub fn canonical_status(
        mut self,
        value: impl Into<Option<RoleCanonicalStatus<S>>>,
    ) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `canonicalStatus` field to an Option value (optional)
    pub fn maybe_canonical_status(
        mut self,
        value: Option<RoleCanonicalStatus<S>>,
    ) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> RoleBuilder<St, S>
where
    St: role_state::State,
    St::CreatedAt: role_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> RoleBuilder<role_state::SetCreatedAt<St>, S> {
        self._fields.4 = Option::Some(value.into());
        RoleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RoleBuilder<St, S>
where
    St: role_state::State,
    St::CreatorDid: role_state::IsUnset,
{
    /// Set the `creatorDID` field (required)
    pub fn creator_did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> RoleBuilder<role_state::SetCreatorDid<St>, S> {
        self._fields.5 = Option::Some(value.into());
        RoleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<S>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `instancePolicy` field (optional)
    pub fn instance_policy(
        mut self,
        value: impl Into<Option<RoleInstancePolicy<S>>>,
    ) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `instancePolicy` field to an Option value (optional)
    pub fn maybe_instance_policy(
        mut self,
        value: Option<RoleInstancePolicy<S>>,
    ) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St, S: BosStr> RoleBuilder<St, S>
where
    St: role_state::State,
    St::Name: role_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<S>,
    ) -> RoleBuilder<role_state::SetName<St>, S> {
        self._fields.8 = Option::Some(value.into());
        RoleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `sourceReference` field (optional)
    pub fn source_reference(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `sourceReference` field to an Option value (optional)
    pub fn maybe_source_reference(mut self, value: Option<S>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<St: role_state::State, S: BosStr> RoleBuilder<St, S> {
    /// Set the `sourceType` field (optional)
    pub fn source_type(mut self, value: impl Into<Option<RoleSourceType<S>>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `sourceType` field to an Option value (optional)
    pub fn maybe_source_type(mut self, value: Option<RoleSourceType<S>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St, S: BosStr> RoleBuilder<St, S>
where
    St: role_state::State,
    St::WorldReference: role_state::IsUnset,
{
    /// Set the `worldReference` field (required)
    pub fn world_reference(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> RoleBuilder<role_state::SetWorldReference<St>, S> {
        self._fields.11 = Option::Some(value.into());
        RoleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RoleBuilder<St, S>
where
    St: role_state::State,
    St::CreatedAt: role_state::IsSet,
    St::CreatorDid: role_state::IsSet,
    St::Name: role_state::IsSet,
    St::WorldReference: role_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Role<S> {
        Role {
            authorship_record: self._fields.0,
            canonical_character_reference: self._fields.1,
            canonical_reference_policy: self._fields.2,
            canonical_status: self._fields.3,
            created_at: self._fields.4.unwrap(),
            creator_did: self._fields.5.unwrap(),
            description: self._fields.6,
            instance_policy: self._fields.7,
            name: self._fields.8.unwrap(),
            source_reference: self._fields.9,
            source_type: self._fields.10,
            world_reference: self._fields.11.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>>) -> Role<S> {
        Role {
            authorship_record: self._fields.0,
            canonical_character_reference: self._fields.1,
            canonical_reference_policy: self._fields.2,
            canonical_status: self._fields.3,
            created_at: self._fields.4.unwrap(),
            creator_did: self._fields.5.unwrap(),
            description: self._fields.6,
            instance_policy: self._fields.7,
            name: self._fields.8.unwrap(),
            source_reference: self._fields.9,
            source_type: self._fields.10,
            world_reference: self._fields.11.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_world_ptah_temp_role() -> 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("world.ptah.temp.role"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A stage role vs a performance of that role. The Opening of the Mouth was performed on a type of figure — the Role is the type. The Character instance is the specific statue that gets its mouth opened.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"),
                                SmolStr::new_static("creatorDID"),
                                SmolStr::new_static("worldReference"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("authorshipRecord"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Permanent link to the role's creator. Provenance travels.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("canonicalCharacterReference"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The AT URI of the single Character record designated as the authoritative expression of this role. When present, this is the canonical instance.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("canonicalReferencePolicy"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Governs how the canonicalCharacterReference behaves over time.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("canonicalStatus"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The canonical standing of this role within its world.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Timestamp of role creation."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("creatorDID"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Who defined this role in the protocol."),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "What this role is in the world's context — its narrative function, its archetypal weight.",
                                        ),
                                    ),
                                    max_length: Some(10240usize),
                                    max_graphemes: Some(1024usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("instancePolicy"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "How instances of this role are governed.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("What this role is called."),
                                    ),
                                    max_length: Some(640usize),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sourceReference"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "If sourceType is publicDomain, the specific source material.",
                                        ),
                                    ),
                                    max_length: Some(10240usize),
                                    max_graphemes: Some(1024usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sourceType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The intellectual property origin of this role.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("worldReference"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The AT URI of the world record this role exists in.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}