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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::buzz_bookhive::list_genres;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GenreWithCount<'a> {
    ///Number of books in this genre
    pub count: i64,
    ///Genre name
    #[serde(borrow)]
    pub genre: CowStr<'a>,
}


#[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>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListGenresOutput<'a> {
    #[serde(borrow)]
    pub genres: Vec<list_genres::GenreWithCount<'a>>,
    ///Next offset for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<i64>,
}

impl<'a> LexiconSchema for GenreWithCount<'a> {
    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 type for buzz.bookhive.listGenres
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<'de> = ListGenresOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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 type for buzz.bookhive.listGenres
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<'de> = 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCount<S> {}
    impl<S: State> State for SetCount<S> {
        type Count = Set<members::count>;
        type Genre = S::Genre;
    }
    ///State transition - sets the `genre` field to Set
    pub struct SetGenre<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetGenre<S> {}
    impl<S: State> State for SetGenre<S> {
        type Count = S::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<'a, S: genre_with_count_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> GenreWithCountBuilder<'a, S>
where
    S: genre_with_count_state::State,
    S::Count: genre_with_count_state::IsSet,
    S::Genre: genre_with_count_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GenreWithCount<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> GenreWithCount<'a> {
        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<S: list_genres_state::State> {
    _state: PhantomData<fn() -> S>,
    _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
    pub fn new() -> Self {
        ListGenresBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
        }
    }
}

impl<S: list_genres_state::State> ListGenresBuilder<S> {
    /// 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<S: list_genres_state::State> ListGenresBuilder<S> {
    /// 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<S: list_genres_state::State> ListGenresBuilder<S> {
    /// 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<S> ListGenresBuilder<S>
where
    S: 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,
        }
    }
}