// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: st.lifepo.profile
//
// 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::string::Datetime;
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::st_lifepo::profile;
/// A single life event entry.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LifeEvent<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end_date: Option<Datetime>,
    pub start_date: Datetime,
    pub title: S,
    #[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(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Profile<S: BosStr = DefaultStr> {
    pub actor: S,
}


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

impl<S: BosStr> LexiconSchema for LifeEvent<S> {
    fn nsid() -> &'static str {
        "st.lifepo.profile"
    }
    fn def_name() -> &'static str {
        "lifeEvent"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_st_lifepo_profile()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `st.lifepo.profile` query.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Profile<S> {
    const NSID: &'static str = "st.lifepo.profile";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ProfileResponse;
}

/** Endpoint marker for the `st.lifepo.profile` query.

Path: `/xrpc/st.lifepo.profile`. The request payload type is `Profile<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ProfileRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ProfileRequest {
    const PATH: &'static str = "/xrpc/st.lifepo.profile";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = Profile<S>;
    type Response = ProfileResponse;
}

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

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

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

impl<S: BosStr> LifeEvent<S> {
    /// Create a new builder for this type
    pub fn builder() -> LifeEventBuilder<life_event_state::Empty, S> {
        LifeEventBuilder::builder()
    }
}

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

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

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

impl<St: life_event_state::State, S: BosStr> LifeEventBuilder<St, S> {
    /// Set the `endDate` field (optional)
    pub fn end_date(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `endDate` field to an Option value (optional)
    pub fn maybe_end_date(mut self, value: Option<Datetime>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> LifeEventBuilder<St, S>
where
    St: life_event_state::State,
    St::StartDate: life_event_state::IsUnset,
{
    /// Set the `startDate` field (required)
    pub fn start_date(
        mut self,
        value: impl Into<Datetime>,
    ) -> LifeEventBuilder<life_event_state::SetStartDate<St>, S> {
        self._fields.2 = Option::Some(value.into());
        LifeEventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LifeEventBuilder<St, S>
where
    St: life_event_state::State,
    St::Title: life_event_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> LifeEventBuilder<life_event_state::SetTitle<St>, S> {
        self._fields.3 = Option::Some(value.into());
        LifeEventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LifeEventBuilder<St, S>
where
    St: life_event_state::State,
    St::StartDate: life_event_state::IsSet,
    St::Title: life_event_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> LifeEvent<S> {
        LifeEvent {
            description: self._fields.0,
            end_date: self._fields.1,
            start_date: self._fields.2.unwrap(),
            title: 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>>,
    ) -> LifeEvent<S> {
        LifeEvent {
            description: self._fields.0,
            end_date: self._fields.1,
            start_date: self._fields.2.unwrap(),
            title: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_st_lifepo_profile() -> 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("st.lifepo.profile"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("lifeEvent"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A single life event entry.")),
                    required: Some(
                        vec![
                            SmolStr::new_static("title"),
                            SmolStr::new_static("startDate")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("endDate"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("startDate"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("actor")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("actor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("The DID or handle of the user."),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> Profile<S> {
    /// Create a new builder for this type
    pub fn builder() -> ProfileBuilder<profile_state::Empty, S> {
        ProfileBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ProfileBuilder<St, S>
where
    St: profile_state::State,
    St::Actor: profile_state::IsUnset,
{
    /// Set the `actor` field (required)
    pub fn actor(
        mut self,
        value: impl Into<S>,
    ) -> ProfileBuilder<profile_state::SetActor<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ProfileBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ProfileBuilder<St, S>
where
    St: profile_state::State,
    St::Actor: profile_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Profile<S> {
        Profile {
            actor: self._fields.0.unwrap(),
        }
    }
}