// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: buzz.bookhive.listGenres
//
// 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::buzz_bookhive::list_genres;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GenreWithCount<S: BosStr = DefaultStr> {
    ///Number of books in this genre
    pub count: i64,
    ///Genre name
    pub genre: 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")]
pub struct ListGenres {
    /// Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Defaults to `0`. Min: 0.
    #[serde(default = "_default_min_books")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_books: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i64>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListGenresOutput<S: BosStr = DefaultStr> {
    pub genres: Vec<list_genres::GenreWithCount<S>>,
    ///Next offset for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for GenreWithCount<S> {
    fn nsid() -> &'static str {
        "buzz.bookhive.listGenres"
    }
    fn def_name() -> &'static str {
        "genreWithCount"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_buzz_bookhive_listGenres()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `buzz.bookhive.listGenres` query.

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

impl jacquard_common::xrpc::XrpcRequest for ListGenres {
    const NSID: &'static str = "buzz.bookhive.listGenres";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListGenresResponse;
}

/** Endpoint marker for the `buzz.bookhive.listGenres` query.

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

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

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

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

impl<S: BosStr> GenreWithCount<S> {
    /// Create a new builder for this type
    pub fn builder() -> GenreWithCountBuilder<genre_with_count_state::Empty, S> {
        GenreWithCountBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> GenreWithCountBuilder<St, S>
where
    St: genre_with_count_state::State,
    St::Genre: genre_with_count_state::IsUnset,
{
    /// Set the `genre` field (required)
    pub fn genre(
        mut self,
        value: impl Into<S>,
    ) -> GenreWithCountBuilder<genre_with_count_state::SetGenre<St>, S> {
        self._fields.1 = Option::Some(value.into());
        GenreWithCountBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GenreWithCountBuilder<St, S>
where
    St: genre_with_count_state::State,
    St::Count: genre_with_count_state::IsSet,
    St::Genre: genre_with_count_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GenreWithCount<S> {
        GenreWithCount {
            count: self._fields.0.unwrap(),
            genre: 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>>,
    ) -> GenreWithCount<S> {
        GenreWithCount {
            count: self._fields.0.unwrap(),
            genre: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_buzz_bookhive_listGenres() -> 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("buzz.bookhive.listGenres"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("genreWithCount"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("genre"), SmolStr::new_static("count")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("count"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("genre"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Genre name")),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("minBooks"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("offset"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

fn _default_min_books() -> Option<i64> {
    Some(0i64)
}

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

/// Builder for constructing an instance of this type.
pub struct ListGenresBuilder<St: list_genres_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<i64>, Option<i64>, Option<i64>),
}

impl ListGenres {
    /// Create a new builder for this type.
    pub fn new() -> ListGenresBuilder<list_genres_state::Empty> {
        ListGenresBuilder::new()
    }
}

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

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

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

impl<St: list_genres_state::State> ListGenresBuilder<St> {
    /// Set the `minBooks` field (optional)
    pub fn min_books(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `minBooks` field to an Option value (optional)
    pub fn maybe_min_books(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: list_genres_state::State> ListGenresBuilder<St> {
    /// Set the `offset` field (optional)
    pub fn offset(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `offset` field to an Option value (optional)
    pub fn maybe_offset(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St> ListGenresBuilder<St>
where
    St: list_genres_state::State,
{
    /// Build the final struct.
    pub fn build(self) -> ListGenres {
        ListGenres {
            limit: self._fields.0,
            min_books: self._fields.1,
            offset: self._fields.2,
        }
    }
}