jacquard-api 0.12.0-beta.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{AtUri, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::social_showcase::ItemImage;
use crate::social_showcase::ItemView;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpdateItem<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub category: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub external_link: Option<UriValue<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub images: Option<Vec<ItemImage<S>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<Data<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<S>,
    ///The AT-URI of the item
    pub uri: AtUri<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub visibility: Option<UpdateItemVisibility<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 UpdateItemVisibility<S: BosStr = DefaultStr> {
    Public,
    Unlisted,
    Private,
    Other(S),
}

impl<S: BosStr> UpdateItemVisibility<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Public => "public",
            Self::Unlisted => "unlisted",
            Self::Private => "private",
            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() {
            "public" => Self::Public,
            "unlisted" => Self::Unlisted,
            "private" => Self::Private,
            _ => Self::Other(s),
        }
    }
}

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

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

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

impl<S: BosStr> jacquard_common::IntoStatic for UpdateItemVisibility<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = UpdateItemVisibility<S::Output>;
    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())
            }
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpdateItemOutput<S: BosStr = DefaultStr> {
    #[serde(flatten)]
    pub value: ItemView<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// 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<S: BosStr> = UpdateItemOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for UpdateItem<S> {
    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<S: BosStr> = UpdateItem<S>;
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        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<S: BosStr, St: update_item_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<S>,
        Option<UriValue<S>>,
        Option<Vec<ItemImage<S>>>,
        Option<Data<S>>,
        Option<Vec<S>>,
        Option<S>,
        Option<AtUri<S>>,
        Option<UpdateItemVisibility<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> UpdateItemBuilder<S, 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),
            _type: PhantomData,
        }
    }
}

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

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

impl<S: BosStr, St: update_item_state::State> UpdateItemBuilder<S, St> {
    /// Set the `externalLink` field (optional)
    pub fn external_link(mut self, value: impl Into<Option<UriValue<S>>>) -> 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<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<S: BosStr, St: update_item_state::State> UpdateItemBuilder<S, St> {
    /// Set the `images` field (optional)
    pub fn images(mut self, value: impl Into<Option<Vec<ItemImage<S>>>>) -> 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<S>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<S: BosStr, St: update_item_state::State> UpdateItemBuilder<S, St> {
    /// Set the `metadata` field (optional)
    pub fn metadata(mut self, value: impl Into<Option<Data<S>>>) -> 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<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<S: BosStr, St: update_item_state::State> UpdateItemBuilder<S, St> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> 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<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

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

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

impl<S: BosStr, St: update_item_state::State> UpdateItemBuilder<S, St> {
    /// Set the `visibility` field (optional)
    pub fn visibility(
        mut self,
        value: impl Into<Option<UpdateItemVisibility<S>>>,
    ) -> 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<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<S: BosStr, St> UpdateItemBuilder<S, St>
where
    St: update_item_state::State,
    St::Uri: update_item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> UpdateItem<S> {
        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<SmolStr, Data<S>>,
    ) -> UpdateItem<S> {
        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),
        }
    }
}