// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.notebook.updateReadingProgress
//
// 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};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::sh_weaver::notebook::ReadingProgress;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpdateReadingProgress<S: BosStr = DefaultStr> {
    ///The entry the user is currently on.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_entry: Option<AtUri<S>>,
    pub notebook: AtUri<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub percent_complete: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<UpdateReadingProgressStatus<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UpdateReadingProgressStatus<S: BosStr = DefaultStr> {
    Reading,
    Finished,
    Abandoned,
    WantToRead,
    Other(S),
}

impl<S: BosStr> UpdateReadingProgressStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Reading => "reading",
            Self::Finished => "finished",
            Self::Abandoned => "abandoned",
            Self::WantToRead => "want-to-read",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "reading" => Self::Reading,
            "finished" => Self::Finished,
            "abandoned" => Self::Abandoned,
            "want-to-read" => Self::WantToRead,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for UpdateReadingProgressStatus<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for UpdateReadingProgressStatus<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for UpdateReadingProgressStatus<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
for UpdateReadingProgressStatus<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for UpdateReadingProgressStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for UpdateReadingProgressStatus<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = UpdateReadingProgressStatus<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            UpdateReadingProgressStatus::Reading => UpdateReadingProgressStatus::Reading,
            UpdateReadingProgressStatus::Finished => {
                UpdateReadingProgressStatus::Finished
            }
            UpdateReadingProgressStatus::Abandoned => {
                UpdateReadingProgressStatus::Abandoned
            }
            UpdateReadingProgressStatus::WantToRead => {
                UpdateReadingProgressStatus::WantToRead
            }
            UpdateReadingProgressStatus::Other(v) => {
                UpdateReadingProgressStatus::Other(v.into_static())
            }
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpdateReadingProgressOutput<S: BosStr = DefaultStr> {
    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.updateReadingProgress` procedure.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for UpdateReadingProgress<S> {
    const NSID: &'static str = "sh.weaver.notebook.updateReadingProgress";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = UpdateReadingProgressResponse;
}

/** Endpoint marker for the `sh.weaver.notebook.updateReadingProgress` procedure.

Path: `/xrpc/sh.weaver.notebook.updateReadingProgress`. The request payload type is `UpdateReadingProgress<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct UpdateReadingProgressRequest;
impl jacquard_common::xrpc::XrpcEndpoint for UpdateReadingProgressRequest {
    const PATH: &'static str = "/xrpc/sh.weaver.notebook.updateReadingProgress";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = UpdateReadingProgress<S>;
    type Response = UpdateReadingProgressResponse;
}

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

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

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

impl<S: BosStr> UpdateReadingProgress<S> {
    /// Create a new builder for this type
    pub fn builder() -> UpdateReadingProgressBuilder<
        update_reading_progress_state::Empty,
        S,
    > {
        UpdateReadingProgressBuilder::builder()
    }
}

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

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

impl<
    St: update_reading_progress_state::State,
    S: BosStr,
> UpdateReadingProgressBuilder<St, S> {
    /// Set the `currentEntry` field (optional)
    pub fn current_entry(mut self, value: impl Into<Option<AtUri<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<AtUri<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<
    St: update_reading_progress_state::State,
    S: BosStr,
> UpdateReadingProgressBuilder<St, S> {
    /// Set the `percentComplete` field (optional)
    pub fn percent_complete(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `percentComplete` field to an Option value (optional)
    pub fn maybe_percent_complete(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<
    St: update_reading_progress_state::State,
    S: BosStr,
> UpdateReadingProgressBuilder<St, S> {
    /// Set the `status` field (optional)
    pub fn status(
        mut self,
        value: impl Into<Option<UpdateReadingProgressStatus<S>>>,
    ) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `status` field to an Option value (optional)
    pub fn maybe_status(
        mut self,
        value: Option<UpdateReadingProgressStatus<S>>,
    ) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> UpdateReadingProgressBuilder<St, S>
where
    St: update_reading_progress_state::State,
    St::Notebook: update_reading_progress_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> UpdateReadingProgress<S> {
        UpdateReadingProgress {
            current_entry: self._fields.0,
            notebook: self._fields.1.unwrap(),
            percent_complete: self._fields.2,
            status: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> UpdateReadingProgress<S> {
        UpdateReadingProgress {
            current_entry: self._fields.0,
            notebook: self._fields.1.unwrap(),
            percent_complete: self._fields.2,
            status: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}