// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.notification.registerPush
//
// 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;
use jacquard_common::types::string::Did;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RegisterPush<'a> {
    ///Set to true when the actor is age restricted
    #[serde(skip_serializing_if = "Option::is_none")]
    pub age_restricted: Option<bool>,
    #[serde(borrow)]
    pub app_id: CowStr<'a>,
    #[serde(borrow)]
    pub platform: RegisterPushPlatform<'a>,
    #[serde(borrow)]
    pub service_did: Did<'a>,
    #[serde(borrow)]
    pub token: CowStr<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RegisterPushPlatform<'a> {
    Ios,
    Android,
    Web,
    Other(CowStr<'a>),
}

impl<'a> RegisterPushPlatform<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Ios => "ios",
            Self::Android => "android",
            Self::Web => "web",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for RegisterPushPlatform<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "ios" => Self::Ios,
            "android" => Self::Android,
            "web" => Self::Web,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for RegisterPushPlatform<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "ios" => Self::Ios,
            "android" => Self::Android,
            "web" => Self::Web,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for RegisterPushPlatform<'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 RegisterPushPlatform<'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 RegisterPushPlatform<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for RegisterPushPlatform<'_> {
    type Output = RegisterPushPlatform<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            RegisterPushPlatform::Ios => RegisterPushPlatform::Ios,
            RegisterPushPlatform::Android => RegisterPushPlatform::Android,
            RegisterPushPlatform::Web => RegisterPushPlatform::Web,
            RegisterPushPlatform::Other(v) => {
                RegisterPushPlatform::Other(v.into_static())
            }
        }
    }
}

/// Response type for app.bsky.notification.registerPush
pub struct RegisterPushResponse;
impl jacquard_common::xrpc::XrpcResp for RegisterPushResponse {
    const NSID: &'static str = "app.bsky.notification.registerPush";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ();
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for RegisterPush<'a> {
    const NSID: &'static str = "app.bsky.notification.registerPush";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = RegisterPushResponse;
}

/// Endpoint type for app.bsky.notification.registerPush
pub struct RegisterPushRequest;
impl jacquard_common::xrpc::XrpcEndpoint for RegisterPushRequest {
    const PATH: &'static str = "/xrpc/app.bsky.notification.registerPush";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = RegisterPush<'de>;
    type Response = RegisterPushResponse;
}

pub mod register_push_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 Token;
        type Platform;
        type AppId;
        type ServiceDid;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Token = Unset;
        type Platform = Unset;
        type AppId = Unset;
        type ServiceDid = Unset;
    }
    ///State transition - sets the `token` field to Set
    pub struct SetToken<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetToken<S> {}
    impl<S: State> State for SetToken<S> {
        type Token = Set<members::token>;
        type Platform = S::Platform;
        type AppId = S::AppId;
        type ServiceDid = S::ServiceDid;
    }
    ///State transition - sets the `platform` field to Set
    pub struct SetPlatform<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPlatform<S> {}
    impl<S: State> State for SetPlatform<S> {
        type Token = S::Token;
        type Platform = Set<members::platform>;
        type AppId = S::AppId;
        type ServiceDid = S::ServiceDid;
    }
    ///State transition - sets the `app_id` field to Set
    pub struct SetAppId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAppId<S> {}
    impl<S: State> State for SetAppId<S> {
        type Token = S::Token;
        type Platform = S::Platform;
        type AppId = Set<members::app_id>;
        type ServiceDid = S::ServiceDid;
    }
    ///State transition - sets the `service_did` field to Set
    pub struct SetServiceDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetServiceDid<S> {}
    impl<S: State> State for SetServiceDid<S> {
        type Token = S::Token;
        type Platform = S::Platform;
        type AppId = S::AppId;
        type ServiceDid = Set<members::service_did>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `token` field
        pub struct token(());
        ///Marker type for the `platform` field
        pub struct platform(());
        ///Marker type for the `app_id` field
        pub struct app_id(());
        ///Marker type for the `service_did` field
        pub struct service_did(());
    }
}

/// Builder for constructing an instance of this type
pub struct RegisterPushBuilder<'a, S: register_push_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<bool>,
        Option<CowStr<'a>>,
        Option<RegisterPushPlatform<'a>>,
        Option<Did<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> RegisterPush<'a> {
    /// Create a new builder for this type
    pub fn new() -> RegisterPushBuilder<'a, register_push_state::Empty> {
        RegisterPushBuilder::new()
    }
}

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

impl<'a, S: register_push_state::State> RegisterPushBuilder<'a, S> {
    /// Set the `ageRestricted` field (optional)
    pub fn age_restricted(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `ageRestricted` field to an Option value (optional)
    pub fn maybe_age_restricted(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> RegisterPushBuilder<'a, S>
where
    S: register_push_state::State,
    S::AppId: register_push_state::IsUnset,
{
    /// Set the `appId` field (required)
    pub fn app_id(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> RegisterPushBuilder<'a, register_push_state::SetAppId<S>> {
        self._fields.1 = Option::Some(value.into());
        RegisterPushBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RegisterPushBuilder<'a, S>
where
    S: register_push_state::State,
    S::Platform: register_push_state::IsUnset,
{
    /// Set the `platform` field (required)
    pub fn platform(
        mut self,
        value: impl Into<RegisterPushPlatform<'a>>,
    ) -> RegisterPushBuilder<'a, register_push_state::SetPlatform<S>> {
        self._fields.2 = Option::Some(value.into());
        RegisterPushBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RegisterPushBuilder<'a, S>
where
    S: register_push_state::State,
    S::ServiceDid: register_push_state::IsUnset,
{
    /// Set the `serviceDid` field (required)
    pub fn service_did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> RegisterPushBuilder<'a, register_push_state::SetServiceDid<S>> {
        self._fields.3 = Option::Some(value.into());
        RegisterPushBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RegisterPushBuilder<'a, S>
where
    S: register_push_state::State,
    S::Token: register_push_state::IsUnset,
{
    /// Set the `token` field (required)
    pub fn token(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> RegisterPushBuilder<'a, register_push_state::SetToken<S>> {
        self._fields.4 = Option::Some(value.into());
        RegisterPushBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RegisterPushBuilder<'a, S>
where
    S: register_push_state::State,
    S::Token: register_push_state::IsSet,
    S::Platform: register_push_state::IsSet,
    S::AppId: register_push_state::IsSet,
    S::ServiceDid: register_push_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RegisterPush<'a> {
        RegisterPush {
            age_restricted: self._fields.0,
            app_id: self._fields.1.unwrap(),
            platform: self._fields.2.unwrap(),
            service_did: self._fields.3.unwrap(),
            token: self._fields.4.unwrap(),
            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>,
        >,
    ) -> RegisterPush<'a> {
        RegisterPush {
            age_restricted: self._fields.0,
            app_id: self._fields.1.unwrap(),
            platform: self._fields.2.unwrap(),
            service_did: self._fields.3.unwrap(),
            token: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}