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

#[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::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")]
pub struct GetReadingHistory<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub status: Option<CowStr<'a>>,
}


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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ReadingHistoryItem<'a> {
    ///The entry the user was last reading.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub current_entry: Option<EntryView<'a>>,
    #[serde(borrow)]
    pub notebook: NotebookView<'a>,
    #[serde(borrow)]
    pub progress: ReadingProgress<'a>,
}

/// Response type for sh.weaver.notebook.getReadingHistory
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<'de> = GetReadingHistoryOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for sh.weaver.notebook.getReadingHistory
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<'de> = GetReadingHistory<'de>;
    type Response = GetReadingHistoryResponse;
}

impl<'a> LexiconSchema for ReadingHistoryItem<'a> {
    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() -> Option<CowStr<'static>> {
    Some(CowStr::from("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<'a, S: get_reading_history_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<i64>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> GetReadingHistoryBuilder<'a, S>
where
    S: get_reading_history_state::State,
{
    /// Build the final struct
    pub fn build(self) -> GetReadingHistory<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNotebook<S> {}
    impl<S: State> State for SetNotebook<S> {
        type Notebook = Set<members::notebook>;
        type Progress = S::Progress;
    }
    ///State transition - sets the `progress` field to Set
    pub struct SetProgress<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetProgress<S> {}
    impl<S: State> State for SetProgress<S> {
        type Notebook = S::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<'a, S: reading_history_item_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<EntryView<'a>>,
        Option<NotebookView<'a>>,
        Option<ReadingProgress<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> ReadingHistoryItemBuilder<'a, S>
where
    S: reading_history_item_state::State,
    S::Notebook: reading_history_item_state::IsSet,
    S::Progress: reading_history_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ReadingHistoryItem<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ReadingHistoryItem<'a> {
        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()
    }
}