// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: fm.teal.alpha.actor.profileStatus
//
// 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};
/// This lexicon is in a not officially released state. It is subject to change. | A declaration of the profile status of the actor.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "fm.teal.alpha.actor.profileStatus",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ProfileStatus<S: BosStr = DefaultStr> {
    ///The onboarding completion status
    pub completed_onboarding: ProfileStatusCompletedOnboarding<S>,
    ///The timestamp when this status was created
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    ///The timestamp when this status 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>>>,
}

/// The onboarding completion status

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ProfileStatusCompletedOnboarding<S: BosStr = DefaultStr> {
    None,
    ProfileOnboarding,
    PlayOnboarding,
    Complete,
    Other(S),
}

impl<S: BosStr> ProfileStatusCompletedOnboarding<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::None => "none",
            Self::ProfileOnboarding => "profileOnboarding",
            Self::PlayOnboarding => "playOnboarding",
            Self::Complete => "complete",
            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() {
            "none" => Self::None,
            "profileOnboarding" => Self::ProfileOnboarding,
            "playOnboarding" => Self::PlayOnboarding,
            "complete" => Self::Complete,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for ProfileStatusCompletedOnboarding<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 ProfileStatusCompletedOnboarding<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for ProfileStatusCompletedOnboarding<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ProfileStatusCompletedOnboarding<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ProfileStatusCompletedOnboarding<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ProfileStatusCompletedOnboarding::None => {
                ProfileStatusCompletedOnboarding::None
            }
            ProfileStatusCompletedOnboarding::ProfileOnboarding => {
                ProfileStatusCompletedOnboarding::ProfileOnboarding
            }
            ProfileStatusCompletedOnboarding::PlayOnboarding => {
                ProfileStatusCompletedOnboarding::PlayOnboarding
            }
            ProfileStatusCompletedOnboarding::Complete => {
                ProfileStatusCompletedOnboarding::Complete
            }
            ProfileStatusCompletedOnboarding::Other(v) => {
                ProfileStatusCompletedOnboarding::Other(v.into_static())
            }
        }
    }
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ProfileStatusGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: ProfileStatus<S>,
}

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct ProfileStatusRecord;
impl XrpcResp for ProfileStatusRecord {
    const NSID: &'static str = "fm.teal.alpha.actor.profileStatus";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ProfileStatusGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for ProfileStatus<S> {
    const NSID: &'static str = "fm.teal.alpha.actor.profileStatus";
    type Record = ProfileStatusRecord;
}

impl Collection for ProfileStatusRecord {
    const NSID: &'static str = "fm.teal.alpha.actor.profileStatus";
    type Record = ProfileStatusRecord;
}

impl<S: BosStr> LexiconSchema for ProfileStatus<S> {
    fn nsid() -> &'static str {
        "fm.teal.alpha.actor.profileStatus"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_fm_teal_alpha_actor_profileStatus()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> ProfileStatus<S> {
    /// Create a new builder for this type
    pub fn builder() -> ProfileStatusBuilder<profile_status_state::Empty, S> {
        ProfileStatusBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ProfileStatusBuilder<St, S>
where
    St: profile_status_state::State,
    St::CompletedOnboarding: profile_status_state::IsUnset,
{
    /// Set the `completedOnboarding` field (required)
    pub fn completed_onboarding(
        mut self,
        value: impl Into<ProfileStatusCompletedOnboarding<S>>,
    ) -> ProfileStatusBuilder<profile_status_state::SetCompletedOnboarding<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ProfileStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: profile_status_state::State, S: BosStr> ProfileStatusBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.1 = 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.1 = value;
        self
    }
}

impl<St: profile_status_state::State, S: BosStr> ProfileStatusBuilder<St, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.2 = 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.2 = value;
        self
    }
}

impl<St, S: BosStr> ProfileStatusBuilder<St, S>
where
    St: profile_status_state::State,
    St::CompletedOnboarding: profile_status_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ProfileStatus<S> {
        ProfileStatus {
            completed_onboarding: self._fields.0.unwrap(),
            created_at: self._fields.1,
            updated_at: self._fields.2,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ProfileStatus<S> {
        ProfileStatus {
            completed_onboarding: self._fields.0.unwrap(),
            created_at: self._fields.1,
            updated_at: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_fm_teal_alpha_actor_profileStatus() -> 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("fm.teal.alpha.actor.profileStatus"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "This lexicon is in a not officially released state. It is subject to change. | A declaration of the profile status of the actor.",
                        ),
                    ),
                    key: Some(CowStr::new_static("literal:self")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(vec![SmolStr::new_static("completedOnboarding")]),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("completedOnboarding"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("The onboarding completion status"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The timestamp when this status was created",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The timestamp when this status was last updated",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}