// @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;
use jacquard_common::types::string::AtUri;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::sh_weaver::notebook::ReadingProgress;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UpdateReadingProgress<'a> {
    ///The entry the user is currently on.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub current_entry: Option<AtUri<'a>>,
    #[serde(borrow)]
    pub notebook: AtUri<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub percent_complete: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub status: Option<UpdateReadingProgressStatus<'a>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UpdateReadingProgressStatus<'a> {
    Reading,
    Finished,
    Abandoned,
    WantToRead,
    Other(CowStr<'a>),
}

impl<'a> UpdateReadingProgressStatus<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for UpdateReadingProgressStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "reading" => Self::Reading,
            "finished" => Self::Finished,
            "abandoned" => Self::Abandoned,
            "want-to-read" => Self::WantToRead,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for UpdateReadingProgressStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "reading" => Self::Reading,
            "finished" => Self::Finished,
            "abandoned" => Self::Abandoned,
            "want-to-read" => Self::WantToRead,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for UpdateReadingProgressStatus<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for UpdateReadingProgressStatus<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for UpdateReadingProgressStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for UpdateReadingProgressStatus<'_> {
    type Output = UpdateReadingProgressStatus<'static>;
    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())
            }
        }
    }
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UpdateReadingProgressOutput<'a> {
    #[serde(borrow)]
    pub progress: ReadingProgress<'a>,
}

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

impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateReadingProgress<'a> {
    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 type for sh.weaver.notebook.updateReadingProgress
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<'de> = UpdateReadingProgress<'de>;
    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<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>;
    }
    /// 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<'a, S: update_reading_progress_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<AtUri<'a>>,
        Option<AtUri<'a>>,
        Option<i64>,
        Option<UpdateReadingProgressStatus<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, 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<'a, S: update_reading_progress_state::State> UpdateReadingProgressBuilder<'a, S> {
    /// Set the `status` field (optional)
    pub fn status(
        mut self,
        value: impl Into<Option<UpdateReadingProgressStatus<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.3 = value;
        self
    }
}

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