// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.toggleListItem
//
// 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::AtUri;
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 ToggleListItem<S: BosStr = DefaultStr> {
    ///AT URI of the game record.
    pub game_uri: AtUri<S>,
    ///AT URI of the list.
    pub list_uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ToggleListItemOutput<S: BosStr = DefaultStr> {
    ///Whether the game was added to or removed from the list.
    pub action: ToggleListItemOutputAction<S>,
    ///CID of the created listItem record. Present when action is 'added'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<S>,
    ///AT URI of the created listItem record. Present when action is 'added'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uri: Option<AtUri<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Whether the game was added to or removed from the list.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ToggleListItemOutputAction<S: BosStr = DefaultStr> {
    Added,
    Removed,
    Other(S),
}

impl<S: BosStr> ToggleListItemOutputAction<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Added => "added",
            Self::Removed => "removed",
            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() {
            "added" => Self::Added,
            "removed" => Self::Removed,
            _ => Self::Other(s),
        }
    }
}

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for ToggleListItemOutputAction<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ToggleListItemOutputAction<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ToggleListItemOutputAction::Added => ToggleListItemOutputAction::Added,
            ToggleListItemOutputAction::Removed => ToggleListItemOutputAction::Removed,
            ToggleListItemOutputAction::Other(v) => {
                ToggleListItemOutputAction::Other(v.into_static())
            }
        }
    }
}

/** Response marker for the `games.gamesgamesgamesgames.toggleListItem` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ToggleListItemOutput<S>` for this endpoint.*/
pub struct ToggleListItemResponse;
impl jacquard_common::xrpc::XrpcResp for ToggleListItemResponse {
    const NSID: &'static str = "games.gamesgamesgamesgames.toggleListItem";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ToggleListItemOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ToggleListItem<S> {
    const NSID: &'static str = "games.gamesgamesgamesgames.toggleListItem";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = ToggleListItemResponse;
}

/** Endpoint marker for the `games.gamesgamesgamesgames.toggleListItem` procedure.

Path: `/xrpc/games.gamesgamesgamesgames.toggleListItem`. The request payload type is `ToggleListItem<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ToggleListItemRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ToggleListItemRequest {
    const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.toggleListItem";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = ToggleListItem<S>;
    type Response = ToggleListItemResponse;
}

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

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

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

impl<S: BosStr> ToggleListItem<S> {
    /// Create a new builder for this type
    pub fn builder() -> ToggleListItemBuilder<toggle_list_item_state::Empty, S> {
        ToggleListItemBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ToggleListItemBuilder<St, S>
where
    St: toggle_list_item_state::State,
    St::GameUri: toggle_list_item_state::IsUnset,
{
    /// Set the `gameUri` field (required)
    pub fn game_uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ToggleListItemBuilder<toggle_list_item_state::SetGameUri<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ToggleListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ToggleListItemBuilder<St, S>
where
    St: toggle_list_item_state::State,
    St::ListUri: toggle_list_item_state::IsUnset,
{
    /// Set the `listUri` field (required)
    pub fn list_uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ToggleListItemBuilder<toggle_list_item_state::SetListUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ToggleListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ToggleListItemBuilder<St, S>
where
    St: toggle_list_item_state::State,
    St::GameUri: toggle_list_item_state::IsSet,
    St::ListUri: toggle_list_item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ToggleListItem<S> {
        ToggleListItem {
            game_uri: self._fields.0.unwrap(),
            list_uri: self._fields.1.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>>,
    ) -> ToggleListItem<S> {
        ToggleListItem {
            game_uri: self._fields.0.unwrap(),
            list_uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}