// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: world.ptah.temp.world
//
// 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};
use crate::world_ptah::temp::world;
/// The deed. Establishes that a world exists, who created it, and what its basic properties are. Ptah conceives the world in his heart — this record is that conception made permanent.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "world.ptah.temp.world",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct World<S: BosStr = DefaultStr> {
    ///Whether this world is open for contribution, controlled by the originator, or governed by community consensus.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub canonical_status: Option<WorldCanonicalStatus<S>>,
    ///Timestamp of world creation.
    pub created_at: Datetime,
    ///The permanent identity of whoever seeded this world. This never changes.
    pub creator_did: Did<S>,
    ///What kind of world this is, in plain language.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///The constitutional posture of the world. Signals how contributions and canon are governed before anyone contributes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub governance_mode: Option<WorldGovernanceMode<S>>,
    ///What the world is called.
    pub name: S,
    ///Loose metadata telling visual rendering layers what kind of world this is — tone, era, genre, aesthetic.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rendering_hints: Option<world::RenderingHints<S>>,
    ///If sourceType is publicDomain, the specific source material this world is derived from.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_reference: Option<S>,
    ///The intellectual property origin of this world.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_type: Option<WorldSourceType<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Whether this world is open for contribution, controlled by the originator, or governed by community consensus.

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

impl<S: BosStr> WorldCanonicalStatus<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 WorldCanonicalStatus<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

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

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

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

/// The constitutional posture of the world. Signals how contributions and canon are governed before anyone contributes.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WorldGovernanceMode<S: BosStr = DefaultStr> {
    Sandbox,
    Governed,
    Constitutional,
    Other(S),
}

impl<S: BosStr> WorldGovernanceMode<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Sandbox => "sandbox",
            Self::Governed => "governed",
            Self::Constitutional => "constitutional",
            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() {
            "sandbox" => Self::Sandbox,
            "governed" => Self::Governed,
            "constitutional" => Self::Constitutional,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

/// The intellectual property origin of this world.

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

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

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for WorldSourceType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = WorldSourceType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            WorldSourceType::SourceTypeOriginalIp => {
                WorldSourceType::SourceTypeOriginalIp
            }
            WorldSourceType::SourceTypePublicDomain => {
                WorldSourceType::SourceTypePublicDomain
            }
            WorldSourceType::SourceTypeCollaborativeCommons => {
                WorldSourceType::SourceTypeCollaborativeCommons
            }
            WorldSourceType::Other(v) => WorldSourceType::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 WorldGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: World<S>,
}

/// Visual and tonal metadata for rendering layers. The world has to feel like something before anything has happened in it yet.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RenderingHints<S: BosStr = DefaultStr> {
    ///Visual texture, materials, atmosphere.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub aesthetic: Option<S>,
    ///The temporal setting or period.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub era: Option<S>,
    ///The narrative genre.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub genre: Option<S>,
    ///The emotional register of the world.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tone: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

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

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

impl<S: BosStr> LexiconSchema for World<S> {
    fn nsid() -> &'static str {
        "world.ptah.temp.world"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_world_ptah_temp_world()
    }
    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(())
    }
}

impl<S: BosStr> LexiconSchema for RenderingHints<S> {
    fn nsid() -> &'static str {
        "world.ptah.temp.world"
    }
    fn def_name() -> &'static str {
        "renderingHints"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_world_ptah_temp_world()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.aesthetic {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2560usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("aesthetic"),
                    max: 2560usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.aesthetic {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("aesthetic"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.era {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2560usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("era"),
                    max: 2560usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.era {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("era"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.genre {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2560usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("genre"),
                    max: 2560usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.genre {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("genre"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.tone {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2560usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tone"),
                    max: 2560usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.tone {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("tone"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod world_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;
    }
    /// 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;
    }
    ///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;
    }
    ///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;
    }
    ///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>;
    }
    /// 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(());
    }
}

/// Builder for constructing an instance of this type.
pub struct WorldBuilder<St: world_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<WorldCanonicalStatus<S>>,
        Option<Datetime>,
        Option<Did<S>>,
        Option<S>,
        Option<WorldGovernanceMode<S>>,
        Option<S>,
        Option<world::RenderingHints<S>>,
        Option<S>,
        Option<WorldSourceType<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> World<S> {
    /// Create a new builder for this type
    pub fn builder() -> WorldBuilder<world_state::Empty, S> {
        WorldBuilder::builder()
    }
}

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

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

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

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

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

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

impl<St: world_state::State, S: BosStr> WorldBuilder<St, S> {
    /// Set the `governanceMode` field (optional)
    pub fn governance_mode(
        mut self,
        value: impl Into<Option<WorldGovernanceMode<S>>>,
    ) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `governanceMode` field to an Option value (optional)
    pub fn maybe_governance_mode(
        mut self,
        value: Option<WorldGovernanceMode<S>>,
    ) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<St: world_state::State, S: BosStr> WorldBuilder<St, S> {
    /// Set the `renderingHints` field (optional)
    pub fn rendering_hints(
        mut self,
        value: impl Into<Option<world::RenderingHints<S>>>,
    ) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `renderingHints` field to an Option value (optional)
    pub fn maybe_rendering_hints(
        mut self,
        value: Option<world::RenderingHints<S>>,
    ) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: world_state::State, S: BosStr> WorldBuilder<St, S> {
    /// Set the `sourceReference` field (optional)
    pub fn source_reference(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.7 = 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.7 = value;
        self
    }
}

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

impl<St, S: BosStr> WorldBuilder<St, S>
where
    St: world_state::State,
    St::CreatedAt: world_state::IsSet,
    St::CreatorDid: world_state::IsSet,
    St::Name: world_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> World<S> {
        World {
            canonical_status: self._fields.0,
            created_at: self._fields.1.unwrap(),
            creator_did: self._fields.2.unwrap(),
            description: self._fields.3,
            governance_mode: self._fields.4,
            name: self._fields.5.unwrap(),
            rendering_hints: self._fields.6,
            source_reference: self._fields.7,
            source_type: self._fields.8,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> World<S> {
        World {
            canonical_status: self._fields.0,
            created_at: self._fields.1.unwrap(),
            creator_did: self._fields.2.unwrap(),
            description: self._fields.3,
            governance_mode: self._fields.4,
            name: self._fields.5.unwrap(),
            rendering_hints: self._fields.6,
            source_reference: self._fields.7,
            source_type: self._fields.8,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_world_ptah_temp_world() -> 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.world"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "The deed. Establishes that a world exists, who created it, and what its basic properties are. Ptah conceives the world in his heart — this record is that conception made permanent.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"),
                                SmolStr::new_static("creatorDID"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("canonicalStatus"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Whether this world is open for contribution, controlled by the originator, or governed by community consensus.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Timestamp of world creation."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("creatorDID"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The permanent identity of whoever seeded this world. This never changes.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "What kind of world this is, in plain language.",
                                        ),
                                    ),
                                    max_length: Some(10240usize),
                                    max_graphemes: Some(1024usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("governanceMode"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The constitutional posture of the world. Signals how contributions and canon are governed before anyone contributes.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("What the world is called."),
                                    ),
                                    max_length: Some(640usize),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("renderingHints"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#renderingHints"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sourceReference"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "If sourceType is publicDomain, the specific source material this world is derived from.",
                                        ),
                                    ),
                                    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 world.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("renderingHints"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Visual and tonal metadata for rendering layers. The world has to feel like something before anything has happened in it yet.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("aesthetic"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Visual texture, materials, atmosphere."),
                                ),
                                max_length: Some(2560usize),
                                max_graphemes: Some(256usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("era"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The temporal setting or period."),
                                ),
                                max_length: Some(2560usize),
                                max_graphemes: Some(256usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("genre"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The narrative genre."),
                                ),
                                max_length: Some(2560usize),
                                max_graphemes: Some(256usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("tone"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The emotional register of the world."),
                                ),
                                max_length: Some(2560usize),
                                max_graphemes: Some(256usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}