// @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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::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 CreateItem<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>>,
    pub images: Vec<ItemImage<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<Data<S>>,
    pub tags: Vec<S>,
    pub title: S,
    pub visibility: CreateItemVisibility<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 CreateItemVisibility<S: BosStr = DefaultStr> {
    Public,
    Unlisted,
    Private,
    Other(S),
}

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

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

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

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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateItemOutput<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 marker for the `social.showcase.library.createItem` procedure.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateItem<S> {
    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 marker for the `social.showcase.library.createItem` procedure.

Path: `/xrpc/social.showcase.library.createItem`. The request payload type is `CreateItem<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
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<S: BosStr> = CreateItem<S>;
    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 Images;
        type Tags;
        type Title;
        type Visibility;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Images = Unset;
        type Tags = Unset;
        type Title = Unset;
        type Visibility = Unset;
    }
    ///State transition - sets the `images` field to Set
    pub struct SetImages<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetImages<St> {}
    impl<St: State> State for SetImages<St> {
        type Images = Set<members::images>;
        type Tags = St::Tags;
        type Title = St::Title;
        type Visibility = St::Visibility;
    }
    ///State transition - sets the `tags` field to Set
    pub struct SetTags<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTags<St> {}
    impl<St: State> State for SetTags<St> {
        type Images = St::Images;
        type Tags = Set<members::tags>;
        type Title = St::Title;
        type Visibility = St::Visibility;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type Images = St::Images;
        type Tags = St::Tags;
        type Title = Set<members::title>;
        type Visibility = St::Visibility;
    }
    ///State transition - sets the `visibility` field to Set
    pub struct SetVisibility<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetVisibility<St> {}
    impl<St: State> State for SetVisibility<St> {
        type Images = St::Images;
        type Tags = St::Tags;
        type Title = St::Title;
        type Visibility = Set<members::visibility>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `images` field
        pub struct images(());
        ///Marker type for the `tags` field
        pub struct tags(());
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `visibility` field
        pub struct visibility(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CreateItemBuilder<St: create_item_state::State, S: BosStr = DefaultStr> {
    _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<CreateItemVisibility<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl CreateItem<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> CreateItemBuilder<create_item_state::Empty, DefaultStr> {
        CreateItemBuilder::new()
    }
}

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

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

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

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

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

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

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

impl<St, S: BosStr> CreateItemBuilder<St, S>
where
    St: create_item_state::State,
    St::Images: create_item_state::IsSet,
    St::Tags: create_item_state::IsSet,
    St::Title: create_item_state::IsSet,
    St::Visibility: create_item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CreateItem<S> {
        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<SmolStr, Data<S>>,
    ) -> CreateItem<S> {
        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),
        }
    }
}