// @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;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
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;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Search<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub age_ratings: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub application_types: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub genres: Option<Vec<CowStr<'a>>>,
    /// 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")]
    #[serde(borrow)]
    pub modes: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub player_perspectives: Option<Vec<CowStr<'a>>>,
    #[serde(borrow)]
    pub q: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub sort: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub themes: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub types: Option<Vec<CowStr<'a>>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SearchOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub results: Vec<SearchOutputResultsItem<'a>>,
    ///Total number of results matching the query above the relevance threshold.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_results: Option<i64>,
}


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

/// 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<'de> = SearchOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for Search<'a> {
    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<'de> = Search<'de>;
    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::{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 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetQ<S> {}
    impl<S: State> State for SetQ<S> {
        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<'a, S: search_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<CowStr<'a>>>,
        Option<Vec<CowStr<'a>>>,
        Option<CowStr<'a>>,
        Option<Vec<CowStr<'a>>>,
        Option<bool>,
        Option<bool>,
        Option<i64>,
        Option<Vec<CowStr<'a>>>,
        Option<Vec<CowStr<'a>>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<Vec<CowStr<'a>>>,
        Option<Vec<CowStr<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

impl<'a> SearchBuilder<'a, 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,
            ),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// Set the `ageRatings` field (optional)
    pub fn age_ratings(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// Set the `applicationTypes` field (optional)
    pub fn application_types(
        mut self,
        value: impl Into<Option<Vec<CowStr<'a>>>>,
    ) -> 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<CowStr<'a>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// Set the `genres` field (optional)
    pub fn genres(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// 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<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// 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<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// 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<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// Set the `modes` field (optional)
    pub fn modes(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// Set the `playerPerspectives` field (optional)
    pub fn player_perspectives(
        mut self,
        value: impl Into<Option<Vec<CowStr<'a>>>>,
    ) -> 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<CowStr<'a>>>) -> Self {
        self._fields.8 = value;
        self
    }
}

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

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

impl<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// Set the `themes` field (optional)
    pub fn themes(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<'a, S: search_state::State> SearchBuilder<'a, S> {
    /// Set the `types` field (optional)
    pub fn types(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<'a, S> SearchBuilder<'a, S>
where
    S: search_state::State,
    S::Q: search_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Search<'a> {
        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,
        }
    }
}