jacquard-api 0.12.0-beta.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.search
//
// 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;

use crate::games_gamesgamesgamesgames::CollectionSummaryView;
use crate::games_gamesgamesgamesgames::EngineSummaryView;
use crate::games_gamesgamesgamesgames::GameSummaryView;
use crate::games_gamesgamesgamesgames::PlatformSummaryView;
use crate::games_gamesgamesgamesgames::ProfileSummaryView;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::{IntoStatic, open_union};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Search<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub age_ratings: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub application_types: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub genres: Option<Vec<S>>,
    /// Defaults to `false`.
    #[serde(default = "_default_include_cancelled")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_cancelled: Option<bool>,
    /// Defaults to `false`.
    #[serde(default = "_default_include_unrated")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_unrated: Option<bool>,
    ///Defaults to `20`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modes: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub player_perspectives: Option<Vec<S>>,
    pub q: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub themes: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub types: Option<Vec<S>>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct SearchOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub results: Vec<SearchOutputResultsItem<S>>,
    ///Total number of results matching the query above the relevance threshold.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_results: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum SearchOutputResultsItem<S: BosStr = DefaultStr> {
    #[serde(rename = "games.gamesgamesgamesgames.defs#gameSummaryView")]
    GameSummaryView(Box<GameSummaryView<S>>),
    #[serde(rename = "games.gamesgamesgamesgames.defs#profileSummaryView")]
    ProfileSummaryView(Box<ProfileSummaryView<S>>),
    #[serde(rename = "games.gamesgamesgamesgames.defs#platformSummaryView")]
    PlatformSummaryView(Box<PlatformSummaryView<S>>),
    #[serde(rename = "games.gamesgamesgamesgames.defs#collectionSummaryView")]
    CollectionSummaryView(Box<CollectionSummaryView<S>>),
    #[serde(rename = "games.gamesgamesgamesgames.defs#engineSummaryView")]
    EngineSummaryView(Box<EngineSummaryView<S>>),
}

/// Response type for games.gamesgamesgamesgames.search
pub struct SearchResponse;
impl jacquard_common::xrpc::XrpcResp for SearchResponse {
    const NSID: &'static str = "games.gamesgamesgamesgames.search";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = SearchOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Search<S> {
    const NSID: &'static str = "games.gamesgamesgamesgames.search";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = SearchResponse;
}

/// Endpoint type for games.gamesgamesgamesgames.search
pub struct SearchRequest;
impl jacquard_common::xrpc::XrpcEndpoint for SearchRequest {
    const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.search";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = Search<S>;
    type Response = SearchResponse;
}

fn _default_include_cancelled() -> Option<bool> {
    Some(false)
}

fn _default_include_unrated() -> Option<bool> {
    Some(false)
}

fn _default_limit() -> Option<i64> {
    Some(20i64)
}

pub mod search_state {

    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
    #[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 Q;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Q = Unset;
    }
    ///State transition - sets the `q` field to Set
    pub struct SetQ<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetQ<St> {}
    impl<St: State> State for SetQ<St> {
        type Q = Set<members::q>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `q` field
        pub struct q(());
    }
}

/// Builder for constructing an instance of this type.
pub struct SearchBuilder<S: BosStr, St: search_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<S>>,
        Option<Vec<S>>,
        Option<S>,
        Option<Vec<S>>,
        Option<bool>,
        Option<bool>,
        Option<i64>,
        Option<Vec<S>>,
        Option<Vec<S>>,
        Option<S>,
        Option<S>,
        Option<Vec<S>>,
        Option<Vec<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl<S: BosStr> Search<S> {
    /// Create a new builder for this type.
    pub fn new() -> SearchBuilder<S, search_state::Empty> {
        SearchBuilder::new()
    }
}

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

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `ageRatings` field (optional)
    pub fn age_ratings(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `ageRatings` field to an Option value (optional)
    pub fn maybe_age_ratings(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `applicationTypes` field (optional)
    pub fn application_types(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `applicationTypes` field to an Option value (optional)
    pub fn maybe_application_types(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `cursor` field to an Option value (optional)
    pub fn maybe_cursor(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `genres` field (optional)
    pub fn genres(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `genres` field to an Option value (optional)
    pub fn maybe_genres(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `includeCancelled` field (optional)
    pub fn include_cancelled(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `includeCancelled` field to an Option value (optional)
    pub fn maybe_include_cancelled(mut self, value: Option<bool>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `includeUnrated` field (optional)
    pub fn include_unrated(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `includeUnrated` field to an Option value (optional)
    pub fn maybe_include_unrated(mut self, value: Option<bool>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `modes` field (optional)
    pub fn modes(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `modes` field to an Option value (optional)
    pub fn maybe_modes(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `playerPerspectives` field (optional)
    pub fn player_perspectives(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `playerPerspectives` field to an Option value (optional)
    pub fn maybe_player_perspectives(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<S: BosStr, St> SearchBuilder<S, St>
where
    St: search_state::State,
    St::Q: search_state::IsUnset,
{
    /// Set the `q` field (required)
    pub fn q(mut self, value: impl Into<S>) -> SearchBuilder<S, search_state::SetQ<St>> {
        self._fields.9 = Option::Some(value.into());
        SearchBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `sort` field (optional)
    pub fn sort(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `sort` field to an Option value (optional)
    pub fn maybe_sort(mut self, value: Option<S>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `themes` field (optional)
    pub fn themes(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `themes` field to an Option value (optional)
    pub fn maybe_themes(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<S: BosStr, St: search_state::State> SearchBuilder<S, St> {
    /// Set the `types` field (optional)
    pub fn types(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `types` field to an Option value (optional)
    pub fn maybe_types(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<S: BosStr, St> SearchBuilder<S, St>
where
    St: search_state::State,
    St::Q: search_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Search<S> {
        Search {
            age_ratings: self._fields.0,
            application_types: self._fields.1,
            cursor: self._fields.2,
            genres: self._fields.3,
            include_cancelled: self._fields.4,
            include_unrated: self._fields.5,
            limit: self._fields.6,
            modes: self._fields.7,
            player_perspectives: self._fields.8,
            q: self._fields.9.unwrap(),
            sort: self._fields.10,
            themes: self._fields.11,
            types: self._fields.12,
        }
    }
}