// @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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ProfileStatus<'a> {
    ///The onboarding completion status
    #[serde(borrow)]
    pub completed_onboarding: ProfileStatusCompletedOnboarding<'a>,
    ///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>,
}

/// The onboarding completion status

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ProfileStatusCompletedOnboarding<'a> {
    None,
    ProfileOnboarding,
    PlayOnboarding,
    Complete,
    Other(CowStr<'a>),
}

impl<'a> ProfileStatusCompletedOnboarding<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for ProfileStatusCompletedOnboarding<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "none" => Self::None,
            "profileOnboarding" => Self::ProfileOnboarding,
            "playOnboarding" => Self::PlayOnboarding,
            "complete" => Self::Complete,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ProfileStatusCompletedOnboarding<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "none" => Self::None,
            "profileOnboarding" => Self::ProfileOnboarding,
            "playOnboarding" => Self::PlayOnboarding,
            "complete" => Self::Complete,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for ProfileStatusCompletedOnboarding<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for ProfileStatusCompletedOnboarding<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for ProfileStatusCompletedOnboarding<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for ProfileStatusCompletedOnboarding<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for ProfileStatusCompletedOnboarding<'_> {
    type Output = ProfileStatusCompletedOnboarding<'static>;
    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<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: ProfileStatus<'a>,
}

impl<'a> ProfileStatus<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, ProfileStatusRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

/// 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<'de> = ProfileStatusGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<ProfileStatusGetRecordOutput<'_>> for ProfileStatus<'_> {
    fn from(output: ProfileStatusGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for ProfileStatus<'_> {
    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<'a> LexiconSchema for ProfileStatus<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCompletedOnboarding<S> {}
    impl<S: State> State for SetCompletedOnboarding<S> {
        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<'a, S: profile_status_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<ProfileStatusCompletedOnboarding<'a>>,
        Option<Datetime>,
        Option<Datetime>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: profile_status_state::State> ProfileStatusBuilder<'a, 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<'a, S: profile_status_state::State> ProfileStatusBuilder<'a, 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<'a, S> ProfileStatusBuilder<'a, S>
where
    S: profile_status_state::State,
    S::CompletedOnboarding: profile_status_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ProfileStatus<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ProfileStatus<'a> {
        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()
    }
}