// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: space.polymodel.actor.getSession
//
// 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::{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::string::{Did, Handle};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::space_polymodel::actor::ProfileView;
use crate::space_polymodel::actor::get_session;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetSessionOutput<S: BosStr = DefaultStr> {
    #[serde(flatten)]
    pub value: get_session::SessionView<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Authenticated viewer identity for client session seeding. If authenticated is true, did, handle, and profile are all present.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SessionAuthenticated<S: BosStr = DefaultStr> {
    pub authenticated: bool,
    pub did: Did<S>,
    pub handle: Handle<S>,
    pub profile: ProfileView<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Logged-out session marker. No identity fields are present when authenticated is false.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SessionUnauthenticated<S: BosStr = DefaultStr> {
    pub authenticated: bool,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum SessionView<S: BosStr = DefaultStr> {
    #[serde(rename = "space.polymodel.actor.getSession#sessionUnauthenticated")]
    SessionUnauthenticated(Box<get_session::SessionUnauthenticated<S>>),
    #[serde(rename = "space.polymodel.actor.getSession#sessionAuthenticated")]
    SessionAuthenticated(Box<get_session::SessionAuthenticated<S>>),
}

/** Request marker for the `space.polymodel.actor.getSession` query.

This endpoint has no request parameters or input body; send this marker with `jacquard::Client`.*/

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
pub struct GetSession;
/** Response marker for the `space.polymodel.actor.getSession` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetSessionOutput<S>` for this endpoint.*/
pub struct GetSessionResponse;
impl jacquard_common::xrpc::XrpcResp for GetSessionResponse {
    const NSID: &'static str = "space.polymodel.actor.getSession";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetSessionOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl jacquard_common::xrpc::XrpcRequest for GetSession {
    const NSID: &'static str = "space.polymodel.actor.getSession";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetSessionResponse;
}

/** Endpoint marker for the `space.polymodel.actor.getSession` query.

Path: `/xrpc/space.polymodel.actor.getSession`. The request payload type is `GetSession`; use this marker with lower-level `XrpcEndpoint` APIs when you need endpoint metadata.*/
pub struct GetSessionRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetSessionRequest {
    const PATH: &'static str = "/xrpc/space.polymodel.actor.getSession";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetSession;
    type Response = GetSessionResponse;
}

impl<S: BosStr> LexiconSchema for SessionAuthenticated<S> {
    fn nsid() -> &'static str {
        "space.polymodel.actor.getSession"
    }
    fn def_name() -> &'static str {
        "sessionAuthenticated"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_space_polymodel_actor_getSession()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for SessionUnauthenticated<S> {
    fn nsid() -> &'static str {
        "space.polymodel.actor.getSession"
    }
    fn def_name() -> &'static str {
        "sessionUnauthenticated"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_space_polymodel_actor_getSession()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod session_authenticated_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 Authenticated;
        type Did;
        type Handle;
        type Profile;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Authenticated = Unset;
        type Did = Unset;
        type Handle = Unset;
        type Profile = Unset;
    }
    ///State transition - sets the `authenticated` field to Set
    pub struct SetAuthenticated<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAuthenticated<St> {}
    impl<St: State> State for SetAuthenticated<St> {
        type Authenticated = Set<members::authenticated>;
        type Did = St::Did;
        type Handle = St::Handle;
        type Profile = St::Profile;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDid<St> {}
    impl<St: State> State for SetDid<St> {
        type Authenticated = St::Authenticated;
        type Did = Set<members::did>;
        type Handle = St::Handle;
        type Profile = St::Profile;
    }
    ///State transition - sets the `handle` field to Set
    pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHandle<St> {}
    impl<St: State> State for SetHandle<St> {
        type Authenticated = St::Authenticated;
        type Did = St::Did;
        type Handle = Set<members::handle>;
        type Profile = St::Profile;
    }
    ///State transition - sets the `profile` field to Set
    pub struct SetProfile<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetProfile<St> {}
    impl<St: State> State for SetProfile<St> {
        type Authenticated = St::Authenticated;
        type Did = St::Did;
        type Handle = St::Handle;
        type Profile = Set<members::profile>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `authenticated` field
        pub struct authenticated(());
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `handle` field
        pub struct handle(());
        ///Marker type for the `profile` field
        pub struct profile(());
    }
}

/// Builder for constructing an instance of this type.
pub struct SessionAuthenticatedBuilder<
    St: session_authenticated_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<bool>, Option<Did<S>>, Option<Handle<S>>, Option<ProfileView<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> SessionAuthenticated<S> {
    /// Create a new builder for this type
    pub fn builder() -> SessionAuthenticatedBuilder<
        session_authenticated_state::Empty,
        S,
    > {
        SessionAuthenticatedBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SessionAuthenticatedBuilder<St, S>
where
    St: session_authenticated_state::State,
    St::Authenticated: session_authenticated_state::IsUnset,
{
    /// Set the `authenticated` field (required)
    pub fn authenticated(
        mut self,
        value: impl Into<bool>,
    ) -> SessionAuthenticatedBuilder<
        session_authenticated_state::SetAuthenticated<St>,
        S,
    > {
        self._fields.0 = Option::Some(value.into());
        SessionAuthenticatedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SessionAuthenticatedBuilder<St, S>
where
    St: session_authenticated_state::State,
    St::Did: session_authenticated_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> SessionAuthenticatedBuilder<session_authenticated_state::SetDid<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SessionAuthenticatedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SessionAuthenticatedBuilder<St, S>
where
    St: session_authenticated_state::State,
    St::Handle: session_authenticated_state::IsUnset,
{
    /// Set the `handle` field (required)
    pub fn handle(
        mut self,
        value: impl Into<Handle<S>>,
    ) -> SessionAuthenticatedBuilder<session_authenticated_state::SetHandle<St>, S> {
        self._fields.2 = Option::Some(value.into());
        SessionAuthenticatedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SessionAuthenticatedBuilder<St, S>
where
    St: session_authenticated_state::State,
    St::Profile: session_authenticated_state::IsUnset,
{
    /// Set the `profile` field (required)
    pub fn profile(
        mut self,
        value: impl Into<ProfileView<S>>,
    ) -> SessionAuthenticatedBuilder<session_authenticated_state::SetProfile<St>, S> {
        self._fields.3 = Option::Some(value.into());
        SessionAuthenticatedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SessionAuthenticatedBuilder<St, S>
where
    St: session_authenticated_state::State,
    St::Authenticated: session_authenticated_state::IsSet,
    St::Did: session_authenticated_state::IsSet,
    St::Handle: session_authenticated_state::IsSet,
    St::Profile: session_authenticated_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SessionAuthenticated<S> {
        SessionAuthenticated {
            authenticated: self._fields.0.unwrap(),
            did: self._fields.1.unwrap(),
            handle: self._fields.2.unwrap(),
            profile: self._fields.3.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>>,
    ) -> SessionAuthenticated<S> {
        SessionAuthenticated {
            authenticated: self._fields.0.unwrap(),
            did: self._fields.1.unwrap(),
            handle: self._fields.2.unwrap(),
            profile: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_space_polymodel_actor_getSession() -> 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("space.polymodel.actor.getSession"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: None,
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("sessionAuthenticated"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Authenticated viewer identity for client session seeding. If authenticated is true, did, handle, and profile are all present.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("authenticated"),
                            SmolStr::new_static("did"), SmolStr::new_static("handle"),
                            SmolStr::new_static("profile")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("authenticated"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Handle),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("profile"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "space.polymodel.actor.defs#profileView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("sessionUnauthenticated"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Logged-out session marker. No identity fields are present when authenticated is false.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("authenticated")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("authenticated"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("sessionView"),
                LexUserType::Union(LexRefUnion {
                    refs: vec![
                        CowStr::new_static("space.polymodel.actor.getSession#sessionUnauthenticated"),
                        CowStr::new_static("space.polymodel.actor.getSession#sessionAuthenticated")
                    ],
                    closed: Some(true),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod session_unauthenticated_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 Authenticated;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Authenticated = Unset;
    }
    ///State transition - sets the `authenticated` field to Set
    pub struct SetAuthenticated<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAuthenticated<St> {}
    impl<St: State> State for SetAuthenticated<St> {
        type Authenticated = Set<members::authenticated>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `authenticated` field
        pub struct authenticated(());
    }
}

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

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

impl<S: BosStr> SessionUnauthenticated<S> {
    /// Create a new builder for this type
    pub fn builder() -> SessionUnauthenticatedBuilder<
        session_unauthenticated_state::Empty,
        S,
    > {
        SessionUnauthenticatedBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SessionUnauthenticatedBuilder<St, S>
where
    St: session_unauthenticated_state::State,
    St::Authenticated: session_unauthenticated_state::IsUnset,
{
    /// Set the `authenticated` field (required)
    pub fn authenticated(
        mut self,
        value: impl Into<bool>,
    ) -> SessionUnauthenticatedBuilder<
        session_unauthenticated_state::SetAuthenticated<St>,
        S,
    > {
        self._fields.0 = Option::Some(value.into());
        SessionUnauthenticatedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SessionUnauthenticatedBuilder<St, S>
where
    St: session_unauthenticated_state::State,
    St::Authenticated: session_unauthenticated_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SessionUnauthenticated<S> {
        SessionUnauthenticated {
            authenticated: self._fields.0.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>>,
    ) -> SessionUnauthenticated<S> {
        SessionUnauthenticated {
            authenticated: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}