// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: social.showcase.library.updateItem
//
// 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, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::social_showcase::ItemImage;
use crate::social_showcase::ItemView;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UpdateItem<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub category: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub external_link: Option<UriValue<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub images: Option<Vec<ItemImage<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub metadata: Option<Data<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tags: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub title: Option<CowStr<'a>>,
    ///The AT-URI of the item
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub visibility: Option<UpdateItemVisibility<'a>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UpdateItemVisibility<'a> {
    Public,
    Unlisted,
    Private,
    Other(CowStr<'a>),
}

impl<'a> UpdateItemVisibility<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Public => "public",
            Self::Unlisted => "unlisted",
            Self::Private => "private",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for UpdateItemVisibility<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "public" => Self::Public,
            "unlisted" => Self::Unlisted,
            "private" => Self::Private,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for UpdateItemVisibility<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "public" => Self::Public,
            "unlisted" => Self::Unlisted,
            "private" => Self::Private,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for UpdateItemVisibility<'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 UpdateItemVisibility<'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 UpdateItemVisibility<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for UpdateItemVisibility<'_> {
    type Output = UpdateItemVisibility<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            UpdateItemVisibility::Public => UpdateItemVisibility::Public,
            UpdateItemVisibility::Unlisted => UpdateItemVisibility::Unlisted,
            UpdateItemVisibility::Private => UpdateItemVisibility::Private,
            UpdateItemVisibility::Other(v) => {
                UpdateItemVisibility::Other(v.into_static())
            }
        }
    }
}


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

/// Response type for social.showcase.library.updateItem
pub struct UpdateItemResponse;
impl jacquard_common::xrpc::XrpcResp for UpdateItemResponse {
    const NSID: &'static str = "social.showcase.library.updateItem";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = UpdateItemOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateItem<'a> {
    const NSID: &'static str = "social.showcase.library.updateItem";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = UpdateItemResponse;
}

/// Endpoint type for social.showcase.library.updateItem
pub struct UpdateItemRequest;
impl jacquard_common::xrpc::XrpcEndpoint for UpdateItemRequest {
    const PATH: &'static str = "/xrpc/social.showcase.library.updateItem";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = UpdateItem<'de>;
    type Response = UpdateItemResponse;
}

pub mod update_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 Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type
pub struct UpdateItemBuilder<'a, S: update_item_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<UriValue<'a>>,
        Option<Vec<ItemImage<'a>>>,
        Option<Data<'a>>,
        Option<Vec<CowStr<'a>>>,
        Option<CowStr<'a>>,
        Option<AtUri<'a>>,
        Option<UpdateItemVisibility<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> UpdateItem<'a> {
    /// Create a new builder for this type
    pub fn new() -> UpdateItemBuilder<'a, update_item_state::Empty> {
        UpdateItemBuilder::new()
    }
}

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

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `category` field (optional)
    pub fn category(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `category` field to an Option value (optional)
    pub fn maybe_category(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `externalLink` field (optional)
    pub fn external_link(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `externalLink` field to an Option value (optional)
    pub fn maybe_external_link(mut self, value: Option<UriValue<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `images` field (optional)
    pub fn images(mut self, value: impl Into<Option<Vec<ItemImage<'a>>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `images` field to an Option value (optional)
    pub fn maybe_images(mut self, value: Option<Vec<ItemImage<'a>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `metadata` field (optional)
    pub fn metadata(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `metadata` field to an Option value (optional)
    pub fn maybe_metadata(mut self, value: Option<Data<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `tags` field to an Option value (optional)
    pub fn maybe_tags(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `title` field (optional)
    pub fn title(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `title` field to an Option value (optional)
    pub fn maybe_title(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<'a, S> UpdateItemBuilder<'a, S>
where
    S: update_item_state::State,
    S::Uri: update_item_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> UpdateItemBuilder<'a, update_item_state::SetUri<S>> {
        self._fields.7 = Option::Some(value.into());
        UpdateItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: update_item_state::State> UpdateItemBuilder<'a, S> {
    /// Set the `visibility` field (optional)
    pub fn visibility(
        mut self,
        value: impl Into<Option<UpdateItemVisibility<'a>>>,
    ) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `visibility` field to an Option value (optional)
    pub fn maybe_visibility(mut self, value: Option<UpdateItemVisibility<'a>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<'a, S> UpdateItemBuilder<'a, S>
where
    S: update_item_state::State,
    S::Uri: update_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> UpdateItem<'a> {
        UpdateItem {
            category: self._fields.0,
            description: self._fields.1,
            external_link: self._fields.2,
            images: self._fields.3,
            metadata: self._fields.4,
            tags: self._fields.5,
            title: self._fields.6,
            uri: self._fields.7.unwrap(),
            visibility: self._fields.8,
            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, Data<'a>>,
    ) -> UpdateItem<'a> {
        UpdateItem {
            category: self._fields.0,
            description: self._fields.1,
            external_link: self._fields.2,
            images: self._fields.3,
            metadata: self._fields.4,
            tags: self._fields.5,
            title: self._fields.6,
            uri: self._fields.7.unwrap(),
            visibility: self._fields.8,
            extra_data: Some(extra_data),
        }
    }
}