// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: community.lexicon.calendar.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::{AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::community_lexicon::location::address::Address;
use crate::community_lexicon::location::fsq::Fsq;
use crate::community_lexicon::location::geo::Geo;
use crate::community_lexicon::location::hthree::Hthree;
use crate::community_lexicon::calendar::event;
/// The event has been cancelled.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Cancelled;
impl core::fmt::Display for Cancelled {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "cancelled")
    }
}

/// A hybrid event that takes place both online and offline.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Hybrid;
impl core::fmt::Display for Hybrid {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "hybrid")
    }
}

/// An in-person event that takes place offline.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Inperson;
impl core::fmt::Display for Inperson {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "inperson")
    }
}

/// A calendar event.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "community.lexicon.calendar.event",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Event<S: BosStr = DefaultStr> {
    ///Client-declared timestamp when the event was created.
    pub created_at: Datetime,
    ///The description of the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///Client-declared timestamp when the event ends.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ends_at: Option<Datetime>,
    ///The locations where the event takes place.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub locations: Option<Vec<EventLocationsItem<S>>>,
    ///The attendance mode of the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mode: Option<event::Mode<S>>,
    ///The name of the event.
    pub name: S,
    ///Whether a response is requested from attendees.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rsvp_expected: Option<bool>,
    ///Client-declared timestamp when the event starts.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub starts_at: Option<Datetime>,
    ///The status of the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<event::Status<S>>,
    ///URIs associated with the event.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uris: Option<Vec<event::Uri<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum EventLocationsItem<S: BosStr = DefaultStr> {
    #[serde(rename = "community.lexicon.calendar.event#uri")]
    Uri(Box<event::Uri<S>>),
    #[serde(rename = "community.lexicon.location.address")]
    Address(Box<Address<S>>),
    #[serde(rename = "community.lexicon.location.fsq")]
    Fsq(Box<Fsq<S>>),
    #[serde(rename = "community.lexicon.location.geo")]
    Geo(Box<Geo<S>>),
    #[serde(rename = "community.lexicon.location.hthree")]
    Hthree(Box<Hthree<S>>),
}

/// 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>,
}

/// The mode of the event.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Mode<S: BosStr = DefaultStr> {
    CommunityLexiconCalendarEventHybrid,
    CommunityLexiconCalendarEventInperson,
    CommunityLexiconCalendarEventVirtual,
    Other(S),
}

impl<S: BosStr> Mode<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::CommunityLexiconCalendarEventHybrid => {
                "community.lexicon.calendar.event#hybrid"
            }
            Self::CommunityLexiconCalendarEventInperson => {
                "community.lexicon.calendar.event#inperson"
            }
            Self::CommunityLexiconCalendarEventVirtual => {
                "community.lexicon.calendar.event#virtual"
            }
            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() {
            "community.lexicon.calendar.event#hybrid" => {
                Self::CommunityLexiconCalendarEventHybrid
            }
            "community.lexicon.calendar.event#inperson" => {
                Self::CommunityLexiconCalendarEventInperson
            }
            "community.lexicon.calendar.event#virtual" => {
                Self::CommunityLexiconCalendarEventVirtual
            }
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for Mode<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 Mode<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> jacquard_common::IntoStatic for Mode<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = Mode<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            Mode::CommunityLexiconCalendarEventHybrid => {
                Mode::CommunityLexiconCalendarEventHybrid
            }
            Mode::CommunityLexiconCalendarEventInperson => {
                Mode::CommunityLexiconCalendarEventInperson
            }
            Mode::CommunityLexiconCalendarEventVirtual => {
                Mode::CommunityLexiconCalendarEventVirtual
            }
            Mode::Other(v) => Mode::Other(v.into_static()),
        }
    }
}

/// The event has been created, but not finalized.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Planned;
impl core::fmt::Display for Planned {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "planned")
    }
}

/// The event has been postponed and a new start date has not been set.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Postponed;
impl core::fmt::Display for Postponed {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "postponed")
    }
}

/// The event has been rescheduled.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Rescheduled;
impl core::fmt::Display for Rescheduled {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "rescheduled")
    }
}

/// The event has been created and scheduled.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Scheduled;
impl core::fmt::Display for Scheduled {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "scheduled")
    }
}

/// The status of the event.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Status<S: BosStr = DefaultStr> {
    CommunityLexiconCalendarEventCancelled,
    CommunityLexiconCalendarEventPlanned,
    CommunityLexiconCalendarEventPostponed,
    CommunityLexiconCalendarEventRescheduled,
    CommunityLexiconCalendarEventScheduled,
    Other(S),
}

impl<S: BosStr> Status<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::CommunityLexiconCalendarEventCancelled => {
                "community.lexicon.calendar.event#cancelled"
            }
            Self::CommunityLexiconCalendarEventPlanned => {
                "community.lexicon.calendar.event#planned"
            }
            Self::CommunityLexiconCalendarEventPostponed => {
                "community.lexicon.calendar.event#postponed"
            }
            Self::CommunityLexiconCalendarEventRescheduled => {
                "community.lexicon.calendar.event#rescheduled"
            }
            Self::CommunityLexiconCalendarEventScheduled => {
                "community.lexicon.calendar.event#scheduled"
            }
            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() {
            "community.lexicon.calendar.event#cancelled" => {
                Self::CommunityLexiconCalendarEventCancelled
            }
            "community.lexicon.calendar.event#planned" => {
                Self::CommunityLexiconCalendarEventPlanned
            }
            "community.lexicon.calendar.event#postponed" => {
                Self::CommunityLexiconCalendarEventPostponed
            }
            "community.lexicon.calendar.event#rescheduled" => {
                Self::CommunityLexiconCalendarEventRescheduled
            }
            "community.lexicon.calendar.event#scheduled" => {
                Self::CommunityLexiconCalendarEventScheduled
            }
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for Status<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 Status<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> jacquard_common::IntoStatic for Status<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = Status<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            Status::CommunityLexiconCalendarEventCancelled => {
                Status::CommunityLexiconCalendarEventCancelled
            }
            Status::CommunityLexiconCalendarEventPlanned => {
                Status::CommunityLexiconCalendarEventPlanned
            }
            Status::CommunityLexiconCalendarEventPostponed => {
                Status::CommunityLexiconCalendarEventPostponed
            }
            Status::CommunityLexiconCalendarEventRescheduled => {
                Status::CommunityLexiconCalendarEventRescheduled
            }
            Status::CommunityLexiconCalendarEventScheduled => {
                Status::CommunityLexiconCalendarEventScheduled
            }
            Status::Other(v) => Status::Other(v.into_static()),
        }
    }
}

/// A URI associated with the event.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Uri<S: BosStr = DefaultStr> {
    ///The display name of the URI.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<S>,
    pub uri: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A virtual event that takes place online.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Virtual;
impl core::fmt::Display for Virtual {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "virtual")
    }
}

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 = "community.lexicon.calendar.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 = "community.lexicon.calendar.event";
    type Record = EventRecord;
}

impl Collection for EventRecord {
    const NSID: &'static str = "community.lexicon.calendar.event";
    type Record = EventRecord;
}

impl<S: BosStr> LexiconSchema for Event<S> {
    fn nsid() -> &'static str {
        "community.lexicon.calendar.event"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_community_lexicon_calendar_event()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Uri<S> {
    fn nsid() -> &'static str {
        "community.lexicon.calendar.event"
    }
    fn def_name() -> &'static str {
        "uri"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_community_lexicon_calendar_event()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        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 Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = 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 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 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 `name` field
        pub struct name(());
    }
}

/// 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<S>,
        Option<Datetime>,
        Option<Vec<EventLocationsItem<S>>>,
        Option<event::Mode<S>>,
        Option<S>,
        Option<bool>,
        Option<Datetime>,
        Option<event::Status<S>>,
        Option<Vec<event::Uri<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),
            _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),
            _type: PhantomData,
        }
    }
}

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.0 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `mode` field (optional)
    pub fn mode(mut self, value: impl Into<Option<event::Mode<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `mode` field to an Option value (optional)
    pub fn maybe_mode(mut self, value: Option<event::Mode<S>>) -> Self {
        self._fields.4 = 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.5 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `startsAt` field (optional)
    pub fn starts_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `startsAt` field to an Option value (optional)
    pub fn maybe_starts_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.7 = 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<event::Status<S>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `status` field to an Option value (optional)
    pub fn maybe_status(mut self, value: Option<event::Status<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

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

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::CreatedAt: event_state::IsSet,
    St::Name: event_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Event<S> {
        Event {
            created_at: self._fields.0.unwrap(),
            description: self._fields.1,
            ends_at: self._fields.2,
            locations: self._fields.3,
            mode: self._fields.4,
            name: self._fields.5.unwrap(),
            rsvp_expected: self._fields.6,
            starts_at: self._fields.7,
            status: self._fields.8,
            uris: self._fields.9,
            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 {
            created_at: self._fields.0.unwrap(),
            description: self._fields.1,
            ends_at: self._fields.2,
            locations: self._fields.3,
            mode: self._fields.4,
            name: self._fields.5.unwrap(),
            rsvp_expected: self._fields.6,
            starts_at: self._fields.7,
            status: self._fields.8,
            uris: self._fields.9,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_community_lexicon_calendar_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("community.lexicon.calendar.event"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("cancelled"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("hybrid"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("inperson"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(CowStr::new_static("A calendar event.")),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("createdAt"),
                                SmolStr::new_static("name")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when the event was created.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("The description of the event."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("endsAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when the event ends.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("locations"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "The locations where the event takes place.",
                                        ),
                                    ),
                                    items: LexArrayItem::Union(LexRefUnion {
                                        refs: vec![
                                            CowStr::new_static("community.lexicon.calendar.event#uri"),
                                            CowStr::new_static("community.lexicon.location.address"),
                                            CowStr::new_static("community.lexicon.location.fsq"),
                                            CowStr::new_static("community.lexicon.location.geo"),
                                            CowStr::new_static("community.lexicon.location.hthree")
                                        ],
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("mode"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "community.lexicon.calendar.event#mode",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("The name of the event."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("rsvpExpected"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("startsAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when the event starts.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("status"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "community.lexicon.calendar.event#status",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("uris"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("URIs associated with the event."),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static(
                                            "community.lexicon.calendar.event#uri",
                                        ),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("mode"),
                LexUserType::String(LexString {
                    description: Some(CowStr::new_static("The mode of the event.")),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("planned"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("postponed"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("rescheduled"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("scheduled"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("status"),
                LexUserType::String(LexString {
                    description: Some(CowStr::new_static("The status of the event.")),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("uri"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A URI associated with the event."),
                    ),
                    required: Some(vec![SmolStr::new_static("uri")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The display name of the URI."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("virtual"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod uri_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> Uri<S> {
    /// Create a new builder for this type
    pub fn builder() -> UriBuilder<uri_state::Empty, S> {
        UriBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> UriBuilder<St, S>
where
    St: uri_state::State,
    St::Uri: uri_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Uri<S> {
        Uri {
            name: self._fields.0,
            uri: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Uri<S> {
        Uri {
            name: self._fields.0,
            uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}