#[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::blob::BlobRef;
use jacquard_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::social_showcase::CollectionItem;
use crate::social_showcase::CollectionView;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpdateCollection<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cover_image: Option<BlobRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub items: Option<Vec<CollectionItem<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<S>>,
pub uri: AtUri<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub visibility: Option<UpdateCollectionVisibility<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 UpdateCollectionVisibility<S: BosStr = DefaultStr> {
Public,
Private,
Other(S),
}
impl<S: BosStr> UpdateCollectionVisibility<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Public => "public",
Self::Private => "private",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"public" => Self::Public,
"private" => Self::Private,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for UpdateCollectionVisibility<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for UpdateCollectionVisibility<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for UpdateCollectionVisibility<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 UpdateCollectionVisibility<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 UpdateCollectionVisibility<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for UpdateCollectionVisibility<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = UpdateCollectionVisibility<S::Output>;
fn into_static(self) -> Self::Output {
match self {
UpdateCollectionVisibility::Public => UpdateCollectionVisibility::Public,
UpdateCollectionVisibility::Private => UpdateCollectionVisibility::Private,
UpdateCollectionVisibility::Other(v) => {
UpdateCollectionVisibility::Other(v.into_static())
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpdateCollectionOutput<S: BosStr = DefaultStr> {
#[serde(flatten)]
pub value: CollectionView<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
pub struct UpdateCollectionResponse;
impl jacquard_common::xrpc::XrpcResp for UpdateCollectionResponse {
const NSID: &'static str = "social.showcase.collection.updateCollection";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = UpdateCollectionOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for UpdateCollection<S> {
const NSID: &'static str = "social.showcase.collection.updateCollection";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = UpdateCollectionResponse;
}
pub struct UpdateCollectionRequest;
impl jacquard_common::xrpc::XrpcEndpoint for UpdateCollectionRequest {
const PATH: &'static str = "/xrpc/social.showcase.collection.updateCollection";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = UpdateCollection<S>;
type Response = UpdateCollectionResponse;
}
pub mod update_collection_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Uri;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Uri = Unset;
}
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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct uri(());
}
}
pub struct UpdateCollectionBuilder<S: BosStr, St: update_collection_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<BlobRef<S>>,
Option<S>,
Option<Vec<CollectionItem<S>>>,
Option<S>,
Option<Vec<S>>,
Option<AtUri<S>>,
Option<UpdateCollectionVisibility<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> UpdateCollection<S> {
pub fn new() -> UpdateCollectionBuilder<S, update_collection_state::Empty> {
UpdateCollectionBuilder::new()
}
}
impl<S: BosStr> UpdateCollectionBuilder<S, update_collection_state::Empty> {
pub fn new() -> Self {
UpdateCollectionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: update_collection_state::State> UpdateCollectionBuilder<S, St> {
pub fn cover_image(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_cover_image(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: update_collection_state::State> UpdateCollectionBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: update_collection_state::State> UpdateCollectionBuilder<S, St> {
pub fn items(mut self, value: impl Into<Option<Vec<CollectionItem<S>>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_items(mut self, value: Option<Vec<CollectionItem<S>>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: update_collection_state::State> UpdateCollectionBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: update_collection_state::State> UpdateCollectionBuilder<S, St> {
pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> UpdateCollectionBuilder<S, St>
where
St: update_collection_state::State,
St::Uri: update_collection_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<S>>,
) -> UpdateCollectionBuilder<S, update_collection_state::SetUri<St>> {
self._fields.5 = Option::Some(value.into());
UpdateCollectionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: update_collection_state::State> UpdateCollectionBuilder<S, St> {
pub fn visibility(
mut self,
value: impl Into<Option<UpdateCollectionVisibility<S>>>,
) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_visibility(
mut self,
value: Option<UpdateCollectionVisibility<S>>,
) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> UpdateCollectionBuilder<S, St>
where
St: update_collection_state::State,
St::Uri: update_collection_state::IsSet,
{
pub fn build(self) -> UpdateCollection<S> {
UpdateCollection {
cover_image: self._fields.0,
description: self._fields.1,
items: self._fields.2,
name: self._fields.3,
tags: self._fields.4,
uri: self._fields.5.unwrap(),
visibility: self._fields.6,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> UpdateCollection<S> {
UpdateCollection {
cover_image: self._fields.0,
description: self._fields.1,
items: self._fields.2,
name: self._fields.3,
tags: self._fields.4,
uri: self._fields.5.unwrap(),
visibility: self._fields.6,
extra_data: Some(extra_data),
}
}
}