// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: social.showcase.collection.updateCollection
//
// 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::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>>,
    ///The AT-URI of the collection
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    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>>>,
}

/** Response marker for the `social.showcase.collection.updateCollection` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `UpdateCollectionOutput<S>` for this endpoint.*/
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;
}

/** Endpoint marker for the `social.showcase.collection.updateCollection` procedure.

Path: `/xrpc/social.showcase.collection.updateCollection`. The request payload type is `UpdateCollection<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
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 {}
    }
    /// 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 UpdateCollectionBuilder<
    St: update_collection_state::State,
    S: BosStr = DefaultStr,
> {
    _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 UpdateCollection<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> UpdateCollectionBuilder<update_collection_state::Empty, DefaultStr> {
        UpdateCollectionBuilder::new()
    }
}

impl<S: BosStr> UpdateCollection<S> {
    /// Create a new builder for this type
    pub fn builder() -> UpdateCollectionBuilder<update_collection_state::Empty, S> {
        UpdateCollectionBuilder::builder()
    }
}

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

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

impl<St: update_collection_state::State, S: BosStr> UpdateCollectionBuilder<St, S> {
    /// Set the `coverImage` field (optional)
    pub fn cover_image(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `coverImage` field to an Option value (optional)
    pub fn maybe_cover_image(mut self, value: Option<BlobRef<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: update_collection_state::State, S: BosStr> UpdateCollectionBuilder<St, S> {
    /// 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<St: update_collection_state::State, S: BosStr> UpdateCollectionBuilder<St, S> {
    /// Set the `items` field (optional)
    pub fn items(mut self, value: impl Into<Option<Vec<CollectionItem<S>>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `items` field to an Option value (optional)
    pub fn maybe_items(mut self, value: Option<Vec<CollectionItem<S>>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

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

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

impl<St, S: BosStr> UpdateCollectionBuilder<St, S>
where
    St: update_collection_state::State,
    St::Uri: update_collection_state::IsSet,
{
    /// Build the final struct.
    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(),
        }
    }
    /// Build the final struct with custom extra_data.
    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),
        }
    }
}