// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.feed.getListItems
//
// 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::string::{AtUri, Datetime};
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::feed::get_list_items;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListItemView<S: BosStr = DefaultStr> {
    pub added_at: Datetime,
    pub game: Data<S>,
    pub 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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetListItems<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    /// Defaults to `30`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    pub list_uri: AtUri<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetListItemsOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub items: Vec<get_list_items::ListItemView<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ListItemView<S> {
    fn nsid() -> &'static str {
        "games.gamesgamesgamesgames.feed.getListItems"
    }
    fn def_name() -> &'static str {
        "listItemView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_games_gamesgamesgamesgames_feed_getListItems()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `games.gamesgamesgamesgames.feed.getListItems` query.

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

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

/** Endpoint marker for the `games.gamesgamesgamesgames.feed.getListItems` query.

Path: `/xrpc/games.gamesgamesgamesgames.feed.getListItems`. The request payload type is `GetListItems<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetListItemsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetListItemsRequest {
    const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.feed.getListItems";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetListItems<S>;
    type Response = GetListItemsResponse;
}

pub mod list_item_view_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 AddedAt;
        type Game;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type AddedAt = Unset;
        type Game = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `added_at` field to Set
    pub struct SetAddedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAddedAt<St> {}
    impl<St: State> State for SetAddedAt<St> {
        type AddedAt = Set<members::added_at>;
        type Game = St::Game;
        type Uri = St::Uri;
    }
    ///State transition - sets the `game` field to Set
    pub struct SetGame<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetGame<St> {}
    impl<St: State> State for SetGame<St> {
        type AddedAt = St::AddedAt;
        type Game = Set<members::game>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type AddedAt = St::AddedAt;
        type Game = St::Game;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `added_at` field
        pub struct added_at(());
        ///Marker type for the `game` field
        pub struct game(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> ListItemView<S> {
    /// Create a new builder for this type
    pub fn builder() -> ListItemViewBuilder<list_item_view_state::Empty, S> {
        ListItemViewBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ListItemViewBuilder<St, S>
where
    St: list_item_view_state::State,
    St::AddedAt: list_item_view_state::IsUnset,
{
    /// Set the `addedAt` field (required)
    pub fn added_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> ListItemViewBuilder<list_item_view_state::SetAddedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ListItemViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ListItemViewBuilder<St, S>
where
    St: list_item_view_state::State,
    St::Game: list_item_view_state::IsUnset,
{
    /// Set the `game` field (required)
    pub fn game(
        mut self,
        value: impl Into<Data<S>>,
    ) -> ListItemViewBuilder<list_item_view_state::SetGame<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ListItemViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ListItemViewBuilder<St, S>
where
    St: list_item_view_state::State,
    St::Uri: list_item_view_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ListItemViewBuilder<list_item_view_state::SetUri<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ListItemViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ListItemViewBuilder<St, S>
where
    St: list_item_view_state::State,
    St::AddedAt: list_item_view_state::IsSet,
    St::Game: list_item_view_state::IsSet,
    St::Uri: list_item_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListItemView<S> {
        ListItemView {
            added_at: self._fields.0.unwrap(),
            game: self._fields.1.unwrap(),
            uri: self._fields.2.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>>,
    ) -> ListItemView<S> {
        ListItemView {
            added_at: self._fields.0.unwrap(),
            game: self._fields.1.unwrap(),
            uri: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_games_gamesgamesgamesgames_feed_getListItems() -> 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.feed.getListItems"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("listItemView"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("addedAt"),
                            SmolStr::new_static("game")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("addedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("game"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("listUri")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("listUri"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("The AT-URI of the list."),
                                        ),
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

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

impl<S: BosStr> GetListItems<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetListItemsBuilder<get_list_items_state::Empty, S> {
        GetListItemsBuilder::builder()
    }
}

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

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

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

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

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

impl<St, S: BosStr> GetListItemsBuilder<St, S>
where
    St: get_list_items_state::State,
    St::ListUri: get_list_items_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetListItems<S> {
        GetListItems {
            cursor: self._fields.0,
            limit: self._fields.1,
            list_uri: self._fields.2.unwrap(),
        }
    }
}