// @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;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::string::AtUri;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::social_showcase::CollectionItem;
use crate::social_showcase::CollectionView;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UpdateCollection<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cover_image: Option<BlobRef<'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 items: Option<Vec<CollectionItem<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tags: Option<Vec<CowStr<'a>>>,
    ///The AT-URI of the collection
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub visibility: Option<UpdateCollectionVisibility<'a>>,
}


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

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

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

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

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

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

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

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


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

/// Response type for social.showcase.collection.updateCollection
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<'de> = UpdateCollectionOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateCollection<'a> {
    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 type for social.showcase.collection.updateCollection
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<'de> = UpdateCollection<'de>;
    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<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 UpdateCollectionBuilder<'a, S: update_collection_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<BlobRef<'a>>,
        Option<CowStr<'a>>,
        Option<Vec<CollectionItem<'a>>>,
        Option<CowStr<'a>>,
        Option<Vec<CowStr<'a>>>,
        Option<AtUri<'a>>,
        Option<UpdateCollectionVisibility<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: update_collection_state::State> UpdateCollectionBuilder<'a, S> {
    /// Set the `coverImage` field (optional)
    pub fn cover_image(mut self, value: impl Into<Option<BlobRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

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

impl<'a, S: update_collection_state::State> UpdateCollectionBuilder<'a, S> {
    /// Set the `visibility` field (optional)
    pub fn visibility(
        mut self,
        value: impl Into<Option<UpdateCollectionVisibility<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.6 = value;
        self
    }
}

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