// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.putPopularity
//
// 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};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::games_gamesgamesgamesgames::put_popularity;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GamePopularity<S: BosStr = DefaultStr> {
    ///Concurrent player count.
    pub ccu: i64,
    ///Steam app ID.
    pub steam_id: 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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PutPopularity<S: BosStr = DefaultStr> {
    ///List of games with popularity data to upsert.
    pub games: Vec<put_popularity::GamePopularity<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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PutPopularityOutput<S: BosStr = DefaultStr> {
    ///Number of records upserted.
    pub upserted: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for GamePopularity<S> {
    fn nsid() -> &'static str {
        "games.gamesgamesgamesgames.putPopularity"
    }
    fn def_name() -> &'static str {
        "gamePopularity"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_games_gamesgamesgamesgames_putPopularity()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.ccu;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("ccu"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

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

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

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

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

pub mod game_popularity_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 Ccu;
        type SteamId;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Ccu = Unset;
        type SteamId = Unset;
    }
    ///State transition - sets the `ccu` field to Set
    pub struct SetCcu<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCcu<St> {}
    impl<St: State> State for SetCcu<St> {
        type Ccu = Set<members::ccu>;
        type SteamId = St::SteamId;
    }
    ///State transition - sets the `steam_id` field to Set
    pub struct SetSteamId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSteamId<St> {}
    impl<St: State> State for SetSteamId<St> {
        type Ccu = St::Ccu;
        type SteamId = Set<members::steam_id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `ccu` field
        pub struct ccu(());
        ///Marker type for the `steam_id` field
        pub struct steam_id(());
    }
}

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

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

impl<S: BosStr> GamePopularity<S> {
    /// Create a new builder for this type
    pub fn builder() -> GamePopularityBuilder<game_popularity_state::Empty, S> {
        GamePopularityBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> GamePopularityBuilder<St, S>
where
    St: game_popularity_state::State,
    St::Ccu: game_popularity_state::IsUnset,
{
    /// Set the `ccu` field (required)
    pub fn ccu(
        mut self,
        value: impl Into<i64>,
    ) -> GamePopularityBuilder<game_popularity_state::SetCcu<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GamePopularityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GamePopularityBuilder<St, S>
where
    St: game_popularity_state::State,
    St::SteamId: game_popularity_state::IsUnset,
{
    /// Set the `steamId` field (required)
    pub fn steam_id(
        mut self,
        value: impl Into<S>,
    ) -> GamePopularityBuilder<game_popularity_state::SetSteamId<St>, S> {
        self._fields.1 = Option::Some(value.into());
        GamePopularityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GamePopularityBuilder<St, S>
where
    St: game_popularity_state::State,
    St::Ccu: game_popularity_state::IsSet,
    St::SteamId: game_popularity_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GamePopularity<S> {
        GamePopularity {
            ccu: self._fields.0.unwrap(),
            steam_id: 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>>,
    ) -> GamePopularity<S> {
        GamePopularity {
            ccu: self._fields.0.unwrap(),
            steam_id: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_games_gamesgamesgamesgames_putPopularity() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("games.gamesgamesgamesgames.putPopularity"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("gamePopularity"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("steamId"), SmolStr::new_static("ccu")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ccu"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("steamId"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Steam app ID.")),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(vec![SmolStr::new_static("games")]),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("games"),
                                        LexObjectProperty::Array(LexArray {
                                            description: Some(
                                                CowStr::new_static(
                                                    "List of games with popularity data to upsert.",
                                                ),
                                            ),
                                            items: LexArrayItem::Ref(LexRef {
                                                r#ref: CowStr::new_static("#gamePopularity"),
                                                ..Default::default()
                                            }),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> PutPopularity<S> {
    /// Create a new builder for this type
    pub fn builder() -> PutPopularityBuilder<put_popularity_state::Empty, S> {
        PutPopularityBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> PutPopularityBuilder<St, S>
where
    St: put_popularity_state::State,
    St::Games: put_popularity_state::IsUnset,
{
    /// Set the `games` field (required)
    pub fn games(
        mut self,
        value: impl Into<Vec<put_popularity::GamePopularity<S>>>,
    ) -> PutPopularityBuilder<put_popularity_state::SetGames<St>, S> {
        self._fields.0 = Option::Some(value.into());
        PutPopularityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PutPopularityBuilder<St, S>
where
    St: put_popularity_state::State,
    St::Games: put_popularity_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> PutPopularity<S> {
        PutPopularity {
            games: 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<SmolStr, Data<S>>,
    ) -> PutPopularity<S> {
        PutPopularity {
            games: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}