// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: net.anisota.beta.game.session
//
// 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};
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::net_anisota::beta::game::session;
/// Summary of activity during this session

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ActivitySummary<S: BosStr = DefaultStr> {
    ///Player's current level at the time of this session update
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_level: Option<i64>,
    ///Player's total XP at the time of this session update
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_xp: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub game_actions: Option<session::GameActions<S>>,
    ///List of unique pages/routes visited
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pages_visited: Option<Vec<S>>,
    ///Total number of events logged in this session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_events: Option<i64>,
    ///Total XP gained during this specific session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub xp_gained_this_session: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Game-specific actions performed

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GameActions<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub daily_rewards_claimed: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub feeds_loaded: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub items_collected: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub level_ups: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub posts_viewed: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub specimens_collected: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A game session record tracking a continuous period of user engagement with the application

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "net.anisota.beta.game.session",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Session<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub activity_summary: Option<session::ActivitySummary<S>>,
    ///Version of the client application
    pub client_version: S,
    ///When the session record was created
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    ///Total session duration in milliseconds (calculated when session ends)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<i64>,
    ///Why the session ended
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end_reason: Option<S>,
    ///When the session ended (ISO 8601)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ended_at: Option<Datetime>,
    ///Timestamp of the last recorded activity in this session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_activity_at: Option<Datetime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<session::Metadata<S>>,
    ///URI of the previous session if this is a continuation (e.g., after brief inactivity)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent_session_uri: Option<S>,
    ///Platform where the session occurred
    pub platform: S,
    ///URIs of log records that occurred during this session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub related_log_uris: Option<Vec<S>>,
    ///URIs of progress records created during this session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub related_progress_uris: Option<Vec<S>>,
    ///URIs of related sessions (e.g., same day, same device)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub related_session_uris: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub session_context: Option<session::SessionContext<S>>,
    ///When the session began (ISO 8601)
    pub started_at: Datetime,
    ///Current status of the session
    pub status: S,
    ///When the session record was last updated
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<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 SessionGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Session<S>,
}

/// Additional session metadata

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Metadata<S: BosStr = DefaultStr> {
    ///List of features used during the session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub features: Option<Vec<S>>,
    ///Network condition during session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub network_condition: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub performance_metrics: Option<session::PerformanceMetrics<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Performance-related data

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PerformanceMetrics<S: BosStr = DefaultStr> {
    ///Average API response time in milliseconds (rounded to nearest integer)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub average_response_time: Option<i64>,
    ///Number of errors encountered
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error_count: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Context about how the session started

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SessionContext<S: BosStr = DefaultStr> {
    ///How the user was authenticated
    #[serde(skip_serializing_if = "Option::is_none")]
    pub authentication_method: Option<S>,
    ///How the user entered the app
    #[serde(skip_serializing_if = "Option::is_none")]
    pub entry_point: Option<S>,
    ///Whether this was a new user's first session
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_new_user: Option<bool>,
    ///Referrer URL if applicable
    #[serde(skip_serializing_if = "Option::is_none")]
    pub referrer: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

impl<S: BosStr> LexiconSchema for ActivitySummary<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.session"
    }
    fn def_name() -> &'static str {
        "activitySummary"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_session()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.current_level {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("current_level"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.current_xp {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("current_xp"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.total_events {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("total_events"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.xp_gained_this_session {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("xp_gained_this_session"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for GameActions<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.session"
    }
    fn def_name() -> &'static str {
        "gameActions"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_session()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.daily_rewards_claimed {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("daily_rewards_claimed"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.feeds_loaded {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("feeds_loaded"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.items_collected {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("items_collected"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.level_ups {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("level_ups"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.posts_viewed {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("posts_viewed"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.specimens_collected {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("specimens_collected"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct SessionRecord;
impl XrpcResp for SessionRecord {
    const NSID: &'static str = "net.anisota.beta.game.session";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = SessionGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Session<S> {
    const NSID: &'static str = "net.anisota.beta.game.session";
    type Record = SessionRecord;
}

impl Collection for SessionRecord {
    const NSID: &'static str = "net.anisota.beta.game.session";
    type Record = SessionRecord;
}

impl<S: BosStr> LexiconSchema for Session<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.session"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_session()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.duration {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("duration"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Metadata<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.session"
    }
    fn def_name() -> &'static str {
        "metadata"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_session()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for PerformanceMetrics<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.session"
    }
    fn def_name() -> &'static str {
        "performanceMetrics"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_session()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.average_response_time {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("average_response_time"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.error_count {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("error_count"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for SessionContext<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.session"
    }
    fn def_name() -> &'static str {
        "sessionContext"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_session()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_net_anisota_beta_game_session() -> 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("net.anisota.beta.game.session"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("activitySummary"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Summary of activity during this session"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("currentLevel"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("currentXP"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("gameActions"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#gameActions"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("pagesVisited"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("List of unique pages/routes visited"),
                                ),
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("totalEvents"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("xpGainedThisSession"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("gameActions"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Game-specific actions performed"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("dailyRewardsClaimed"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("feedsLoaded"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("itemsCollected"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("levelUps"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("postsViewed"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("specimensCollected"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A game session record tracking a continuous period of user engagement with the application",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("startedAt"),
                                SmolStr::new_static("status"),
                                SmolStr::new_static("platform"),
                                SmolStr::new_static("clientVersion")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("activitySummary"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#activitySummary"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("clientVersion"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Version of the client application"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the session record was created"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("duration"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("endReason"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Why the session ended"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("endedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the session ended (ISO 8601)"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("lastActivityAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp of the last recorded activity in this session",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("metadata"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#metadata"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("parentSessionUri"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "URI of the previous session if this is a continuation (e.g., after brief inactivity)",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("platform"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Platform where the session occurred"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("relatedLogUris"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "URIs of log records that occurred during this session",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("relatedProgressUris"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "URIs of progress records created during this session",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("relatedSessionUris"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "URIs of related sessions (e.g., same day, same device)",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sessionContext"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#sessionContext"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("startedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the session began (ISO 8601)"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("status"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Current status of the session"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "When the session record was last updated",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("metadata"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Additional session metadata")),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("features"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "List of features used during the session",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("networkCondition"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Network condition during session"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("performanceMetrics"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#performanceMetrics"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("performanceMetrics"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Performance-related data")),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("averageResponseTime"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("errorCount"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("sessionContext"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Context about how the session started"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("authenticationMethod"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("How the user was authenticated"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("entryPoint"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("How the user entered the app"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isNewUser"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("referrer"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Referrer URL if applicable"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod session_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 ClientVersion;
        type Platform;
        type StartedAt;
        type Status;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type ClientVersion = Unset;
        type Platform = Unset;
        type StartedAt = Unset;
        type Status = Unset;
    }
    ///State transition - sets the `client_version` field to Set
    pub struct SetClientVersion<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetClientVersion<St> {}
    impl<St: State> State for SetClientVersion<St> {
        type ClientVersion = Set<members::client_version>;
        type Platform = St::Platform;
        type StartedAt = St::StartedAt;
        type Status = St::Status;
    }
    ///State transition - sets the `platform` field to Set
    pub struct SetPlatform<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPlatform<St> {}
    impl<St: State> State for SetPlatform<St> {
        type ClientVersion = St::ClientVersion;
        type Platform = Set<members::platform>;
        type StartedAt = St::StartedAt;
        type Status = St::Status;
    }
    ///State transition - sets the `started_at` field to Set
    pub struct SetStartedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStartedAt<St> {}
    impl<St: State> State for SetStartedAt<St> {
        type ClientVersion = St::ClientVersion;
        type Platform = St::Platform;
        type StartedAt = Set<members::started_at>;
        type Status = St::Status;
    }
    ///State transition - sets the `status` field to Set
    pub struct SetStatus<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStatus<St> {}
    impl<St: State> State for SetStatus<St> {
        type ClientVersion = St::ClientVersion;
        type Platform = St::Platform;
        type StartedAt = St::StartedAt;
        type Status = Set<members::status>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `client_version` field
        pub struct client_version(());
        ///Marker type for the `platform` field
        pub struct platform(());
        ///Marker type for the `started_at` field
        pub struct started_at(());
        ///Marker type for the `status` field
        pub struct status(());
    }
}

/// Builder for constructing an instance of this type.
pub struct SessionBuilder<St: session_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<session::ActivitySummary<S>>,
        Option<S>,
        Option<Datetime>,
        Option<i64>,
        Option<S>,
        Option<Datetime>,
        Option<Datetime>,
        Option<session::Metadata<S>>,
        Option<S>,
        Option<S>,
        Option<Vec<S>>,
        Option<Vec<S>>,
        Option<Vec<S>>,
        Option<session::SessionContext<S>>,
        Option<Datetime>,
        Option<S>,
        Option<Datetime>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Session<S> {
    /// Create a new builder for this type
    pub fn builder() -> SessionBuilder<session_state::Empty, S> {
        SessionBuilder::builder()
    }
}

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

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

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `activitySummary` field (optional)
    pub fn activity_summary(
        mut self,
        value: impl Into<Option<session::ActivitySummary<S>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `activitySummary` field to an Option value (optional)
    pub fn maybe_activity_summary(
        mut self,
        value: Option<session::ActivitySummary<S>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> SessionBuilder<St, S>
where
    St: session_state::State,
    St::ClientVersion: session_state::IsUnset,
{
    /// Set the `clientVersion` field (required)
    pub fn client_version(
        mut self,
        value: impl Into<S>,
    ) -> SessionBuilder<session_state::SetClientVersion<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SessionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `createdAt` field to an Option value (optional)
    pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `endReason` field (optional)
    pub fn end_reason(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `endReason` field to an Option value (optional)
    pub fn maybe_end_reason(mut self, value: Option<S>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `endedAt` field (optional)
    pub fn ended_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `endedAt` field to an Option value (optional)
    pub fn maybe_ended_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `lastActivityAt` field (optional)
    pub fn last_activity_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `lastActivityAt` field to an Option value (optional)
    pub fn maybe_last_activity_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `metadata` field (optional)
    pub fn metadata(mut self, value: impl Into<Option<session::Metadata<S>>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `metadata` field to an Option value (optional)
    pub fn maybe_metadata(mut self, value: Option<session::Metadata<S>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `parentSessionUri` field (optional)
    pub fn parent_session_uri(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `parentSessionUri` field to an Option value (optional)
    pub fn maybe_parent_session_uri(mut self, value: Option<S>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St, S: BosStr> SessionBuilder<St, S>
where
    St: session_state::State,
    St::Platform: session_state::IsUnset,
{
    /// Set the `platform` field (required)
    pub fn platform(
        mut self,
        value: impl Into<S>,
    ) -> SessionBuilder<session_state::SetPlatform<St>, S> {
        self._fields.9 = Option::Some(value.into());
        SessionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `relatedLogUris` field (optional)
    pub fn related_log_uris(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `relatedLogUris` field to an Option value (optional)
    pub fn maybe_related_log_uris(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `relatedProgressUris` field (optional)
    pub fn related_progress_uris(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `relatedProgressUris` field to an Option value (optional)
    pub fn maybe_related_progress_uris(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `relatedSessionUris` field (optional)
    pub fn related_session_uris(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `relatedSessionUris` field to an Option value (optional)
    pub fn maybe_related_session_uris(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `sessionContext` field (optional)
    pub fn session_context(
        mut self,
        value: impl Into<Option<session::SessionContext<S>>>,
    ) -> Self {
        self._fields.13 = value.into();
        self
    }
    /// Set the `sessionContext` field to an Option value (optional)
    pub fn maybe_session_context(
        mut self,
        value: Option<session::SessionContext<S>>,
    ) -> Self {
        self._fields.13 = value;
        self
    }
}

impl<St, S: BosStr> SessionBuilder<St, S>
where
    St: session_state::State,
    St::StartedAt: session_state::IsUnset,
{
    /// Set the `startedAt` field (required)
    pub fn started_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SessionBuilder<session_state::SetStartedAt<St>, S> {
        self._fields.14 = Option::Some(value.into());
        SessionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SessionBuilder<St, S>
where
    St: session_state::State,
    St::Status: session_state::IsUnset,
{
    /// Set the `status` field (required)
    pub fn status(
        mut self,
        value: impl Into<S>,
    ) -> SessionBuilder<session_state::SetStatus<St>, S> {
        self._fields.15 = Option::Some(value.into());
        SessionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.16 = value.into();
        self
    }
    /// Set the `updatedAt` field to an Option value (optional)
    pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.16 = value;
        self
    }
}

impl<St, S: BosStr> SessionBuilder<St, S>
where
    St: session_state::State,
    St::ClientVersion: session_state::IsSet,
    St::Platform: session_state::IsSet,
    St::StartedAt: session_state::IsSet,
    St::Status: session_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Session<S> {
        Session {
            activity_summary: self._fields.0,
            client_version: self._fields.1.unwrap(),
            created_at: self._fields.2,
            duration: self._fields.3,
            end_reason: self._fields.4,
            ended_at: self._fields.5,
            last_activity_at: self._fields.6,
            metadata: self._fields.7,
            parent_session_uri: self._fields.8,
            platform: self._fields.9.unwrap(),
            related_log_uris: self._fields.10,
            related_progress_uris: self._fields.11,
            related_session_uris: self._fields.12,
            session_context: self._fields.13,
            started_at: self._fields.14.unwrap(),
            status: self._fields.15.unwrap(),
            updated_at: self._fields.16,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Session<S> {
        Session {
            activity_summary: self._fields.0,
            client_version: self._fields.1.unwrap(),
            created_at: self._fields.2,
            duration: self._fields.3,
            end_reason: self._fields.4,
            ended_at: self._fields.5,
            last_activity_at: self._fields.6,
            metadata: self._fields.7,
            parent_session_uri: self._fields.8,
            platform: self._fields.9.unwrap(),
            related_log_uris: self._fields.10,
            related_progress_uris: self._fields.11,
            related_session_uris: self._fields.12,
            session_context: self._fields.13,
            started_at: self._fields.14.unwrap(),
            status: self._fields.15.unwrap(),
            updated_at: self._fields.16,
            extra_data: Some(extra_data),
        }
    }
}