// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.getReviews
//
// 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::{Did, 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::get_reviews;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetReviews<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    /// Defaults to `20`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    pub uri: AtUri<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetReviewsOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub reviews: Vec<get_reviews::PopfeedReview<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 PopfeedReview<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contains_spoilers: Option<bool>,
    pub created_at: Datetime,
    pub did: Did<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub facets: Option<Vec<Data<S>>>,
    pub rating: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<S>,
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `games.gamesgamesgamesgames.getReviews` query.

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

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

/** Endpoint marker for the `games.gamesgamesgamesgames.getReviews` query.

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

impl<S: BosStr> LexiconSchema for PopfeedReview<S> {
    fn nsid() -> &'static str {
        "games.gamesgamesgamesgames.getReviews"
    }
    fn def_name() -> &'static str {
        "popfeedReview"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_games_gamesgamesgamesgames_getReviews()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.rating;
            if *value > 10i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("rating"),
                    max: 10i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.rating;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("rating"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

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

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

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

impl<S: BosStr> GetReviews<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetReviewsBuilder<get_reviews_state::Empty, S> {
        GetReviewsBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> GetReviewsBuilder<St, S>
where
    St: get_reviews_state::State,
    St::Uri: get_reviews_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetReviews<S> {
        GetReviews {
            cursor: self._fields.0,
            limit: self._fields.1,
            uri: self._fields.2.unwrap(),
        }
    }
}

pub mod popfeed_review_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 CreatedAt;
        type Did;
        type Rating;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Did = Unset;
        type Rating = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Did = St::Did;
        type Rating = St::Rating;
        type Uri = St::Uri;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDid<St> {}
    impl<St: State> State for SetDid<St> {
        type CreatedAt = St::CreatedAt;
        type Did = Set<members::did>;
        type Rating = St::Rating;
        type Uri = St::Uri;
    }
    ///State transition - sets the `rating` field to Set
    pub struct SetRating<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRating<St> {}
    impl<St: State> State for SetRating<St> {
        type CreatedAt = St::CreatedAt;
        type Did = St::Did;
        type Rating = Set<members::rating>;
        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 CreatedAt = St::CreatedAt;
        type Did = St::Did;
        type Rating = St::Rating;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `rating` field
        pub struct rating(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> PopfeedReview<S> {
    /// Create a new builder for this type
    pub fn builder() -> PopfeedReviewBuilder<popfeed_review_state::Empty, S> {
        PopfeedReviewBuilder::builder()
    }
}

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

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

impl<St: popfeed_review_state::State, S: BosStr> PopfeedReviewBuilder<St, S> {
    /// Set the `containsSpoilers` field (optional)
    pub fn contains_spoilers(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `containsSpoilers` field to an Option value (optional)
    pub fn maybe_contains_spoilers(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> PopfeedReviewBuilder<St, S>
where
    St: popfeed_review_state::State,
    St::CreatedAt: popfeed_review_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> PopfeedReviewBuilder<popfeed_review_state::SetCreatedAt<St>, S> {
        self._fields.1 = Option::Some(value.into());
        PopfeedReviewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PopfeedReviewBuilder<St, S>
where
    St: popfeed_review_state::State,
    St::Did: popfeed_review_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> PopfeedReviewBuilder<popfeed_review_state::SetDid<St>, S> {
        self._fields.2 = Option::Some(value.into());
        PopfeedReviewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> PopfeedReviewBuilder<St, S>
where
    St: popfeed_review_state::State,
    St::Rating: popfeed_review_state::IsUnset,
{
    /// Set the `rating` field (required)
    pub fn rating(
        mut self,
        value: impl Into<i64>,
    ) -> PopfeedReviewBuilder<popfeed_review_state::SetRating<St>, S> {
        self._fields.4 = Option::Some(value.into());
        PopfeedReviewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: popfeed_review_state::State, S: BosStr> PopfeedReviewBuilder<St, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `tags` field to an Option value (optional)
    pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

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

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

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

impl<St, S: BosStr> PopfeedReviewBuilder<St, S>
where
    St: popfeed_review_state::State,
    St::CreatedAt: popfeed_review_state::IsSet,
    St::Did: popfeed_review_state::IsSet,
    St::Rating: popfeed_review_state::IsSet,
    St::Uri: popfeed_review_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> PopfeedReview<S> {
        PopfeedReview {
            contains_spoilers: self._fields.0,
            created_at: self._fields.1.unwrap(),
            did: self._fields.2.unwrap(),
            facets: self._fields.3,
            rating: self._fields.4.unwrap(),
            tags: self._fields.5,
            text: self._fields.6,
            title: self._fields.7,
            uri: self._fields.8.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>>,
    ) -> PopfeedReview<S> {
        PopfeedReview {
            contains_spoilers: self._fields.0,
            created_at: self._fields.1.unwrap(),
            did: self._fields.2.unwrap(),
            facets: self._fields.3,
            rating: self._fields.4.unwrap(),
            tags: self._fields.5,
            text: self._fields.6,
            title: self._fields.7,
            uri: self._fields.8.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_games_gamesgamesgamesgames_getReviews() -> 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.getReviews"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("uri")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Pagination cursor (offset)."),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("uri"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("AT URI of the game record."),
                                        ),
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("popfeedReview"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("did"),
                            SmolStr::new_static("rating"),
                            SmolStr::new_static("createdAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("containsSpoilers"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("facets"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("social.popfeed.richtext.facet"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rating"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(10i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("tags"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}