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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, AtUri, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon};
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")]
pub struct GetReviews<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///Defaults to `20`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetReviewsOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub reviews: Vec<get_reviews::PopfeedReview<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PopfeedReview<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contains_spoilers: Option<bool>,
    pub created_at: Datetime,
    #[serde(borrow)]
    pub did: Did<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub facets: Option<Vec<Data<'a>>>,
    pub rating: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tags: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub text: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub title: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}

/// Response type for games.gamesgamesgamesgames.getReviews
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<'de> = GetReviewsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for games.gamesgamesgamesgames.getReviews
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<'de> = GetReviews<'de>;
    type Response = GetReviewsResponse;
}

impl<'a> LexiconSchema for PopfeedReview<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        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<'a, S: get_reviews_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<i64>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> GetReviewsBuilder<'a, S>
where
    S: get_reviews_state::State,
    S::Uri: get_reviews_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetReviews<'a> {
        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 Uri;
        type Did;
        type Rating;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
        type Did = Unset;
        type Rating = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Uri = Set<members::uri>;
        type Did = S::Did;
        type Rating = S::Rating;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDid<S> {}
    impl<S: State> State for SetDid<S> {
        type Uri = S::Uri;
        type Did = Set<members::did>;
        type Rating = S::Rating;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `rating` field to Set
    pub struct SetRating<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRating<S> {}
    impl<S: State> State for SetRating<S> {
        type Uri = S::Uri;
        type Did = S::Did;
        type Rating = Set<members::rating>;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Uri = S::Uri;
        type Did = S::Did;
        type Rating = S::Rating;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `rating` field
        pub struct rating(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct PopfeedReviewBuilder<'a, S: popfeed_review_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<bool>,
        Option<Datetime>,
        Option<Did<'a>>,
        Option<Vec<Data<'a>>>,
        Option<i64>,
        Option<Vec<CowStr<'a>>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<AtUri<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: popfeed_review_state::State> PopfeedReviewBuilder<'a, 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<'a, S> PopfeedReviewBuilder<'a, S>
where
    S: popfeed_review_state::State,
    S::CreatedAt: popfeed_review_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> PopfeedReviewBuilder<'a, popfeed_review_state::SetCreatedAt<S>> {
        self._fields.1 = Option::Some(value.into());
        PopfeedReviewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

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

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

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

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

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

impl<'a, S> PopfeedReviewBuilder<'a, S>
where
    S: popfeed_review_state::State,
    S::Uri: popfeed_review_state::IsSet,
    S::Did: popfeed_review_state::IsSet,
    S::Rating: popfeed_review_state::IsSet,
    S::CreatedAt: popfeed_review_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> PopfeedReview<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> PopfeedReview<'a> {
        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()
    }
}