// @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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::Did;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RegisterPush<S: BosStr = DefaultStr> {
    ///Set to true when the actor is age restricted
    #[serde(skip_serializing_if = "Option::is_none")]
    pub age_restricted: Option<bool>,
    pub app_id: S,
    pub platform: RegisterPushPlatform<S>,
    pub service_did: Did<S>,
    pub token: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RegisterPushPlatform<S: BosStr = DefaultStr> {
    Ios,
    Android,
    Web,
    Other(S),
}

impl<S: BosStr> RegisterPushPlatform<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Ios => "ios",
            Self::Android => "android",
            Self::Web => "web",
            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() {
            "ios" => Self::Ios,
            "android" => Self::Android,
            "web" => Self::Web,
            _ => Self::Other(s),
        }
    }
}

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for RegisterPushPlatform<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = RegisterPushPlatform<S::Output>;
    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 marker for the `app.bsky.notification.registerPush` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `()` for this endpoint.*/
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<S: BosStr> = ();
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for RegisterPush<S> {
    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 marker for the `app.bsky.notification.registerPush` procedure.

Path: `/xrpc/app.bsky.notification.registerPush`. The request payload type is `RegisterPush<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
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<S: BosStr> = RegisterPush<S>;
    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 AppId;
        type Platform;
        type ServiceDid;
        type Token;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type AppId = Unset;
        type Platform = Unset;
        type ServiceDid = Unset;
        type Token = Unset;
    }
    ///State transition - sets the `app_id` field to Set
    pub struct SetAppId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAppId<St> {}
    impl<St: State> State for SetAppId<St> {
        type AppId = Set<members::app_id>;
        type Platform = St::Platform;
        type ServiceDid = St::ServiceDid;
        type Token = St::Token;
    }
    ///State transition - sets the `platform` field to Set
    pub struct SetPlatform<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPlatform<St> {}
    impl<St: State> State for SetPlatform<St> {
        type AppId = St::AppId;
        type Platform = Set<members::platform>;
        type ServiceDid = St::ServiceDid;
        type Token = St::Token;
    }
    ///State transition - sets the `service_did` field to Set
    pub struct SetServiceDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetServiceDid<St> {}
    impl<St: State> State for SetServiceDid<St> {
        type AppId = St::AppId;
        type Platform = St::Platform;
        type ServiceDid = Set<members::service_did>;
        type Token = St::Token;
    }
    ///State transition - sets the `token` field to Set
    pub struct SetToken<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetToken<St> {}
    impl<St: State> State for SetToken<St> {
        type AppId = St::AppId;
        type Platform = St::Platform;
        type ServiceDid = St::ServiceDid;
        type Token = Set<members::token>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `app_id` field
        pub struct app_id(());
        ///Marker type for the `platform` field
        pub struct platform(());
        ///Marker type for the `service_did` field
        pub struct service_did(());
        ///Marker type for the `token` field
        pub struct token(());
    }
}

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

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

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

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

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

impl<St: register_push_state::State, S: BosStr> RegisterPushBuilder<St, 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<St, S: BosStr> RegisterPushBuilder<St, S>
where
    St: register_push_state::State,
    St::AppId: register_push_state::IsUnset,
{
    /// Set the `appId` field (required)
    pub fn app_id(
        mut self,
        value: impl Into<S>,
    ) -> RegisterPushBuilder<register_push_state::SetAppId<St>, S> {
        self._fields.1 = Option::Some(value.into());
        RegisterPushBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

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

impl<St, S: BosStr> RegisterPushBuilder<St, S>
where
    St: register_push_state::State,
    St::AppId: register_push_state::IsSet,
    St::Platform: register_push_state::IsSet,
    St::ServiceDid: register_push_state::IsSet,
    St::Token: register_push_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> RegisterPush<S> {
        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<SmolStr, Data<S>>,
    ) -> RegisterPush<S> {
        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),
        }
    }
}