// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: social.showcase.library.createItem
//
// 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::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 CreateItem<'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(borrow)]
    pub images: Vec<ItemImage<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub metadata: Option<Data<'a>>,
    #[serde(borrow)]
    pub tags: Vec<CowStr<'a>>,
    #[serde(borrow)]
    pub title: CowStr<'a>,
    #[serde(borrow)]
    pub visibility: CreateItemVisibility<'a>,
}


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

impl<'a> CreateItemVisibility<'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 CreateItemVisibility<'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 CreateItemVisibility<'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 CreateItemVisibility<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

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

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

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


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

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

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

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

pub mod create_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 Title;
        type Images;
        type Visibility;
        type Tags;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Title = Unset;
        type Images = Unset;
        type Visibility = Unset;
        type Tags = Unset;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTitle<S> {}
    impl<S: State> State for SetTitle<S> {
        type Title = Set<members::title>;
        type Images = S::Images;
        type Visibility = S::Visibility;
        type Tags = S::Tags;
    }
    ///State transition - sets the `images` field to Set
    pub struct SetImages<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetImages<S> {}
    impl<S: State> State for SetImages<S> {
        type Title = S::Title;
        type Images = Set<members::images>;
        type Visibility = S::Visibility;
        type Tags = S::Tags;
    }
    ///State transition - sets the `visibility` field to Set
    pub struct SetVisibility<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetVisibility<S> {}
    impl<S: State> State for SetVisibility<S> {
        type Title = S::Title;
        type Images = S::Images;
        type Visibility = Set<members::visibility>;
        type Tags = S::Tags;
    }
    ///State transition - sets the `tags` field to Set
    pub struct SetTags<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTags<S> {}
    impl<S: State> State for SetTags<S> {
        type Title = S::Title;
        type Images = S::Images;
        type Visibility = S::Visibility;
        type Tags = Set<members::tags>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `images` field
        pub struct images(());
        ///Marker type for the `visibility` field
        pub struct visibility(());
        ///Marker type for the `tags` field
        pub struct tags(());
    }
}

/// Builder for constructing an instance of this type
pub struct CreateItemBuilder<'a, S: create_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<CreateItemVisibility<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> CreateItem<'a> {
    /// Create a new builder for this type
    pub fn new() -> CreateItemBuilder<'a, create_item_state::Empty> {
        CreateItemBuilder::new()
    }
}

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

impl<'a, S: create_item_state::State> CreateItemBuilder<'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: create_item_state::State> CreateItemBuilder<'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: create_item_state::State> CreateItemBuilder<'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> CreateItemBuilder<'a, S>
where
    S: create_item_state::State,
    S::Images: create_item_state::IsUnset,
{
    /// Set the `images` field (required)
    pub fn images(
        mut self,
        value: impl Into<Vec<ItemImage<'a>>>,
    ) -> CreateItemBuilder<'a, create_item_state::SetImages<S>> {
        self._fields.3 = Option::Some(value.into());
        CreateItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: create_item_state::State> CreateItemBuilder<'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> CreateItemBuilder<'a, S>
where
    S: create_item_state::State,
    S::Tags: create_item_state::IsUnset,
{
    /// Set the `tags` field (required)
    pub fn tags(
        mut self,
        value: impl Into<Vec<CowStr<'a>>>,
    ) -> CreateItemBuilder<'a, create_item_state::SetTags<S>> {
        self._fields.5 = Option::Some(value.into());
        CreateItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CreateItemBuilder<'a, S>
where
    S: create_item_state::State,
    S::Title: create_item_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> CreateItemBuilder<'a, create_item_state::SetTitle<S>> {
        self._fields.6 = Option::Some(value.into());
        CreateItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CreateItemBuilder<'a, S>
where
    S: create_item_state::State,
    S::Visibility: create_item_state::IsUnset,
{
    /// Set the `visibility` field (required)
    pub fn visibility(
        mut self,
        value: impl Into<CreateItemVisibility<'a>>,
    ) -> CreateItemBuilder<'a, create_item_state::SetVisibility<S>> {
        self._fields.7 = Option::Some(value.into());
        CreateItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CreateItemBuilder<'a, S>
where
    S: create_item_state::State,
    S::Title: create_item_state::IsSet,
    S::Images: create_item_state::IsSet,
    S::Visibility: create_item_state::IsSet,
    S::Tags: create_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CreateItem<'a> {
        CreateItem {
            category: self._fields.0,
            description: self._fields.1,
            external_link: self._fields.2,
            images: self._fields.3.unwrap(),
            metadata: self._fields.4,
            tags: self._fields.5.unwrap(),
            title: self._fields.6.unwrap(),
            visibility: self._fields.7.unwrap(),
            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>>,
    ) -> CreateItem<'a> {
        CreateItem {
            category: self._fields.0,
            description: self._fields.1,
            external_link: self._fields.2,
            images: self._fields.3.unwrap(),
            metadata: self._fields.4,
            tags: self._fields.5.unwrap(),
            title: self._fields.6.unwrap(),
            visibility: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}