// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: world.ptah.temp.event
//
// 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 boxing match program combined with a history book entry. Before the fight it is a schedule. After the fight it is a permanent record. Ptah-Seker-Osiris — creation, shadow, rebirth. The event holds all three phases simultaneously.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "world.ptah.temp.event",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Event<S: BosStr = DefaultStr> {
    ///Timestamp of when the event concluded.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub completed_at: Option<Datetime>,
    ///Timestamp of event creation.
    pub created_at: Datetime,
    ///Who organized this event.
    pub creator_did: Did<S>,
    ///What kind of event. Open-ended.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_type: Option<EventEventType<S>>,
    ///The competitive or structural format of the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub format: Option<EventFormat<S>>,
    ///The AT URI of the location where this event happened.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location_reference: Option<AtUri<S>>,
    ///The narrative standing of this event in the world's timeline.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lore_status: Option<EventLoreStatus<S>>,
    ///What this event is called.
    pub name: S,
    ///AT URIs of the character records participating. Not people — characters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub participants: Option<Vec<AtUri<S>>>,
    ///The outcome. Populated when status moves to completed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub result: Option<S>,
    ///What is at risk or being contested.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stakes: Option<S>,
    ///The current phase of the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<EventStatus<S>>,
    ///AT URIs of individual witness action records. Each witness action is a real record created by a real DID at a real timestamp. Witnessing is a verifiable technical contribution, not just a tally.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub witnesses: Option<Vec<AtUri<S>>>,
    ///The AT URI of the world this event occurred in.
    pub world_reference: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// What kind of event. Open-ended.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EventEventType<S: BosStr = DefaultStr> {
    Tournament,
    Battle,
    Gathering,
    Contest,
    Ritual,
    Other(S),
}

impl<S: BosStr> EventEventType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Tournament => "tournament",
            Self::Battle => "battle",
            Self::Gathering => "gathering",
            Self::Contest => "contest",
            Self::Ritual => "ritual",
            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() {
            "tournament" => Self::Tournament,
            "battle" => Self::Battle,
            "gathering" => Self::Gathering,
            "contest" => Self::Contest,
            "ritual" => Self::Ritual,
            _ => Self::Other(s),
        }
    }
}

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for EventEventType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = EventEventType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            EventEventType::Tournament => EventEventType::Tournament,
            EventEventType::Battle => EventEventType::Battle,
            EventEventType::Gathering => EventEventType::Gathering,
            EventEventType::Contest => EventEventType::Contest,
            EventEventType::Ritual => EventEventType::Ritual,
            EventEventType::Other(v) => EventEventType::Other(v.into_static()),
        }
    }
}

/// The competitive or structural format of the event.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EventFormat<S: BosStr = DefaultStr> {
    Bracket,
    RoundRobin,
    OpenChallenge,
    SingleElimination,
    Other(S),
}

impl<S: BosStr> EventFormat<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Bracket => "bracket",
            Self::RoundRobin => "roundRobin",
            Self::OpenChallenge => "openChallenge",
            Self::SingleElimination => "singleElimination",
            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() {
            "bracket" => Self::Bracket,
            "roundRobin" => Self::RoundRobin,
            "openChallenge" => Self::OpenChallenge,
            "singleElimination" => Self::SingleElimination,
            _ => Self::Other(s),
        }
    }
}

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for EventFormat<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = EventFormat<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            EventFormat::Bracket => EventFormat::Bracket,
            EventFormat::RoundRobin => EventFormat::RoundRobin,
            EventFormat::OpenChallenge => EventFormat::OpenChallenge,
            EventFormat::SingleElimination => EventFormat::SingleElimination,
            EventFormat::Other(v) => EventFormat::Other(v.into_static()),
        }
    }
}

/// The narrative standing of this event in the world's timeline.

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

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

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

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

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

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

/// The current phase of the event.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EventStatus<S: BosStr = DefaultStr> {
    Upcoming,
    Active,
    Completed,
    Other(S),
}

impl<S: BosStr> EventStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Upcoming => "upcoming",
            Self::Active => "active",
            Self::Completed => "completed",
            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() {
            "upcoming" => Self::Upcoming,
            "active" => Self::Active,
            "completed" => Self::Completed,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

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

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

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

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

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

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

impl<S: BosStr> LexiconSchema for Event<S> {
    fn nsid() -> &'static str {
        "world.ptah.temp.event"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_world_ptah_temp_event()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.event_type {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("event_type"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.event_type {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("event_type"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.format {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("format"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.format {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("format"),
                        max: 64usize,
                        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.result {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10240usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("result"),
                    max: 10240usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.result {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1024usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("result"),
                        max: 1024usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.stakes {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10240usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("stakes"),
                    max: 10240usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.stakes {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1024usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("stakes"),
                        max: 1024usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod event_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 EventBuilder<St: event_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Datetime>,
        Option<Datetime>,
        Option<Did<S>>,
        Option<EventEventType<S>>,
        Option<EventFormat<S>>,
        Option<AtUri<S>>,
        Option<EventLoreStatus<S>>,
        Option<S>,
        Option<Vec<AtUri<S>>>,
        Option<S>,
        Option<S>,
        Option<EventStatus<S>>,
        Option<Vec<AtUri<S>>>,
        Option<AtUri<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Event<S> {
    /// Create a new builder for this type
    pub fn builder() -> EventBuilder<event_state::Empty, S> {
        EventBuilder::builder()
    }
}

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

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `completedAt` field (optional)
    pub fn completed_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `completedAt` field to an Option value (optional)
    pub fn maybe_completed_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `eventType` field (optional)
    pub fn event_type(mut self, value: impl Into<Option<EventEventType<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `eventType` field to an Option value (optional)
    pub fn maybe_event_type(mut self, value: Option<EventEventType<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `format` field (optional)
    pub fn format(mut self, value: impl Into<Option<EventFormat<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `format` field to an Option value (optional)
    pub fn maybe_format(mut self, value: Option<EventFormat<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `locationReference` field (optional)
    pub fn location_reference(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `locationReference` field to an Option value (optional)
    pub fn maybe_location_reference(mut self, value: Option<AtUri<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `loreStatus` field (optional)
    pub fn lore_status(mut self, value: impl Into<Option<EventLoreStatus<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `loreStatus` field to an Option value (optional)
    pub fn maybe_lore_status(mut self, value: Option<EventLoreStatus<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `participants` field (optional)
    pub fn participants(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `participants` field to an Option value (optional)
    pub fn maybe_participants(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
        self._fields.8 = value;
        self
    }
}

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `stakes` field (optional)
    pub fn stakes(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `stakes` field to an Option value (optional)
    pub fn maybe_stakes(mut self, value: Option<S>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `status` field (optional)
    pub fn status(mut self, value: impl Into<Option<EventStatus<S>>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `status` field to an Option value (optional)
    pub fn maybe_status(mut self, value: Option<EventStatus<S>>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `witnesses` field (optional)
    pub fn witnesses(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `witnesses` field to an Option value (optional)
    pub fn maybe_witnesses(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
        self._fields.12 = value;
        self
    }
}

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

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::CreatedAt: event_state::IsSet,
    St::CreatorDid: event_state::IsSet,
    St::Name: event_state::IsSet,
    St::WorldReference: event_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Event<S> {
        Event {
            completed_at: self._fields.0,
            created_at: self._fields.1.unwrap(),
            creator_did: self._fields.2.unwrap(),
            event_type: self._fields.3,
            format: self._fields.4,
            location_reference: self._fields.5,
            lore_status: self._fields.6,
            name: self._fields.7.unwrap(),
            participants: self._fields.8,
            result: self._fields.9,
            stakes: self._fields.10,
            status: self._fields.11,
            witnesses: self._fields.12,
            world_reference: self._fields.13.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>>) -> Event<S> {
        Event {
            completed_at: self._fields.0,
            created_at: self._fields.1.unwrap(),
            creator_did: self._fields.2.unwrap(),
            event_type: self._fields.3,
            format: self._fields.4,
            location_reference: self._fields.5,
            lore_status: self._fields.6,
            name: self._fields.7.unwrap(),
            participants: self._fields.8,
            result: self._fields.9,
            stakes: self._fields.10,
            status: self._fields.11,
            witnesses: self._fields.12,
            world_reference: self._fields.13.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_world_ptah_temp_event() -> 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.event"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A boxing match program combined with a history book entry. Before the fight it is a schedule. After the fight it is a permanent record. Ptah-Seker-Osiris — creation, shadow, rebirth. The event holds all three phases simultaneously.",
                        ),
                    ),
                    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("completedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Timestamp of when the event concluded."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Timestamp of event creation."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("creatorDID"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Who organized this event."),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("eventType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("What kind of event. Open-ended."),
                                    ),
                                    max_length: Some(640usize),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("format"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The competitive or structural format of the event.",
                                        ),
                                    ),
                                    max_length: Some(640usize),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("locationReference"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The AT URI of the location where this event happened.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("loreStatus"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The narrative standing of this event in the world's timeline.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("What this event is called."),
                                    ),
                                    max_length: Some(640usize),
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("participants"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT URIs of the character records participating. Not people — characters.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("result"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The outcome. Populated when status moves to completed.",
                                        ),
                                    ),
                                    max_length: Some(10240usize),
                                    max_graphemes: Some(1024usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("stakes"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("What is at risk or being contested."),
                                    ),
                                    max_length: Some(10240usize),
                                    max_graphemes: Some(1024usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("status"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("The current phase of the event."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("witnesses"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT URIs of individual witness action records. Each witness action is a real record created by a real DID at a real timestamp. Witnessing is a verifiable technical contribution, not just a tally.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("worldReference"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The AT URI of the world this event occurred in.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}