// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.notebook.getReadingHistory
//
// 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::sh_weaver::notebook::EntryView;
use crate::sh_weaver::notebook::NotebookView;
use crate::sh_weaver::notebook::ReadingProgress;
use crate::sh_weaver::notebook::get_reading_history;

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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetReadingHistoryOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub history: Vec<get_reading_history::ReadingHistoryItem<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 ReadingHistoryItem<S: BosStr = DefaultStr> {
    ///The entry the user was last reading.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_entry: Option<EntryView<S>>,
    pub notebook: NotebookView<S>,
    pub progress: ReadingProgress<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `sh.weaver.notebook.getReadingHistory` query.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetReadingHistory<S> {
    const NSID: &'static str = "sh.weaver.notebook.getReadingHistory";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetReadingHistoryResponse;
}

/** Endpoint marker for the `sh.weaver.notebook.getReadingHistory` query.

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

impl<S: BosStr> LexiconSchema for ReadingHistoryItem<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notebook.getReadingHistory"
    }
    fn def_name() -> &'static str {
        "readingHistoryItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notebook_getReadingHistory()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

fn _default_status<S: jacquard_common::FromStaticStr>() -> Option<S> {
    Some(S::from_static("all"))
}

pub mod get_reading_history_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 GetReadingHistoryBuilder<
    St: get_reading_history_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<i64>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> GetReadingHistory<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetReadingHistoryBuilder<get_reading_history_state::Empty, S> {
        GetReadingHistoryBuilder::builder()
    }
}

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

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

impl<St: get_reading_history_state::State, S: BosStr> GetReadingHistoryBuilder<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_reading_history_state::State, S: BosStr> GetReadingHistoryBuilder<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: get_reading_history_state::State, S: BosStr> GetReadingHistoryBuilder<St, S> {
    /// Set the `status` field (optional)
    pub fn status(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `status` field to an Option value (optional)
    pub fn maybe_status(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> GetReadingHistoryBuilder<St, S>
where
    St: get_reading_history_state::State,
{
    /// Build the final struct.
    pub fn build(self) -> GetReadingHistory<S> {
        GetReadingHistory {
            cursor: self._fields.0,
            limit: self._fields.1,
            status: self._fields.2,
        }
    }
}

pub mod reading_history_item_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 Notebook;
        type Progress;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Notebook = Unset;
        type Progress = Unset;
    }
    ///State transition - sets the `notebook` field to Set
    pub struct SetNotebook<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetNotebook<St> {}
    impl<St: State> State for SetNotebook<St> {
        type Notebook = Set<members::notebook>;
        type Progress = St::Progress;
    }
    ///State transition - sets the `progress` field to Set
    pub struct SetProgress<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetProgress<St> {}
    impl<St: State> State for SetProgress<St> {
        type Notebook = St::Notebook;
        type Progress = Set<members::progress>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `notebook` field
        pub struct notebook(());
        ///Marker type for the `progress` field
        pub struct progress(());
    }
}

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

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

impl<S: BosStr> ReadingHistoryItem<S> {
    /// Create a new builder for this type
    pub fn builder() -> ReadingHistoryItemBuilder<reading_history_item_state::Empty, S> {
        ReadingHistoryItemBuilder::builder()
    }
}

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

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

impl<St: reading_history_item_state::State, S: BosStr> ReadingHistoryItemBuilder<St, S> {
    /// Set the `currentEntry` field (optional)
    pub fn current_entry(mut self, value: impl Into<Option<EntryView<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `currentEntry` field to an Option value (optional)
    pub fn maybe_current_entry(mut self, value: Option<EntryView<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> ReadingHistoryItemBuilder<St, S>
where
    St: reading_history_item_state::State,
    St::Notebook: reading_history_item_state::IsUnset,
{
    /// Set the `notebook` field (required)
    pub fn notebook(
        mut self,
        value: impl Into<NotebookView<S>>,
    ) -> ReadingHistoryItemBuilder<reading_history_item_state::SetNotebook<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ReadingHistoryItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReadingHistoryItemBuilder<St, S>
where
    St: reading_history_item_state::State,
    St::Progress: reading_history_item_state::IsUnset,
{
    /// Set the `progress` field (required)
    pub fn progress(
        mut self,
        value: impl Into<ReadingProgress<S>>,
    ) -> ReadingHistoryItemBuilder<reading_history_item_state::SetProgress<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ReadingHistoryItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReadingHistoryItemBuilder<St, S>
where
    St: reading_history_item_state::State,
    St::Notebook: reading_history_item_state::IsSet,
    St::Progress: reading_history_item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ReadingHistoryItem<S> {
        ReadingHistoryItem {
            current_entry: self._fields.0,
            notebook: self._fields.1.unwrap(),
            progress: 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>>,
    ) -> ReadingHistoryItem<S> {
        ReadingHistoryItem {
            current_entry: self._fields.0,
            notebook: self._fields.1.unwrap(),
            progress: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_notebook_getReadingHistory() -> 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("sh.weaver.notebook.getReadingHistory"),
        defs: {
            let mut map = BTreeMap::new();
            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("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("status"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Filter by reading status."),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("readingHistoryItem"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("notebook"),
                            SmolStr::new_static("progress")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("currentEntry"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.notebook.defs#entryView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("notebook"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.notebook.defs#notebookView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("progress"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.notebook.defs#readingProgress",
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}