jacquard-api 0.11.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.graph.toggleLike
//
// 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::AtUri;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ToggleLike<'a> {
    ///AT URI of the game record to like/unlike.
    #[serde(borrow)]
    pub subject: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ToggleLikeOutput<'a> {
    ///Whether the game was liked or unliked.
    #[serde(borrow)]
    pub action: ToggleLikeOutputAction<'a>,
    ///CID of the created like record. Present when action is 'liked'.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<CowStr<'a>>,
    ///AT URI of the created like record. Present when action is 'liked'.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub uri: Option<AtUri<'a>>,
}

/// Whether the game was liked or unliked.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ToggleLikeOutputAction<'a> {
    Liked,
    Unliked,
    Other(CowStr<'a>),
}

impl<'a> ToggleLikeOutputAction<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Liked => "liked",
            Self::Unliked => "unliked",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for ToggleLikeOutputAction<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "liked" => Self::Liked,
            "unliked" => Self::Unliked,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ToggleLikeOutputAction<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "liked" => Self::Liked,
            "unliked" => Self::Unliked,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

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

/// Response type for games.gamesgamesgamesgames.graph.toggleLike
pub struct ToggleLikeResponse;
impl jacquard_common::xrpc::XrpcResp for ToggleLikeResponse {
    const NSID: &'static str = "games.gamesgamesgamesgames.graph.toggleLike";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ToggleLikeOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for ToggleLike<'a> {
    const NSID: &'static str = "games.gamesgamesgamesgames.graph.toggleLike";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = ToggleLikeResponse;
}

/// Endpoint type for games.gamesgamesgamesgames.graph.toggleLike
pub struct ToggleLikeRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ToggleLikeRequest {
    const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.graph.toggleLike";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = ToggleLike<'de>;
    type Response = ToggleLikeResponse;
}

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

/// Builder for constructing an instance of this type
pub struct ToggleLikeBuilder<'a, S: toggle_like_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AtUri<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> ToggleLike<'a> {
    /// Create a new builder for this type
    pub fn new() -> ToggleLikeBuilder<'a, toggle_like_state::Empty> {
        ToggleLikeBuilder::new()
    }
}

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

impl<'a, S> ToggleLikeBuilder<'a, S>
where
    S: toggle_like_state::State,
    S::Subject: toggle_like_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> ToggleLikeBuilder<'a, toggle_like_state::SetSubject<S>> {
        self._fields.0 = Option::Some(value.into());
        ToggleLikeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ToggleLikeBuilder<'a, S>
where
    S: toggle_like_state::State,
    S::Subject: toggle_like_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ToggleLike<'a> {
        ToggleLike {
            subject: self._fields.0.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>,
        >,
    ) -> ToggleLike<'a> {
        ToggleLike {
            subject: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}