// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: uk.skyblur.post.store
//
// 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::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Store<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub additional: Option<S>,
    pub text: S,
    ///The URI must include the logged-in user's DID in the format at://did...
    pub uri: AtUri<S>,
    pub visibility: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct StoreOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<S>,
    pub success: bool,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `uk.skyblur.post.store` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `StoreOutput<S>` for this endpoint.*/
pub struct StoreResponse;
impl jacquard_common::xrpc::XrpcResp for StoreResponse {
    const NSID: &'static str = "uk.skyblur.post.store";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = StoreOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Store<S> {
    const NSID: &'static str = "uk.skyblur.post.store";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = StoreResponse;
}

/** Endpoint marker for the `uk.skyblur.post.store` procedure.

Path: `/xrpc/uk.skyblur.post.store`. The request payload type is `Store<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct StoreRequest;
impl jacquard_common::xrpc::XrpcEndpoint for StoreRequest {
    const PATH: &'static str = "/xrpc/uk.skyblur.post.store";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = Store<S>;
    type Response = StoreResponse;
}

pub mod store_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 Text;
        type Uri;
        type Visibility;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Text = Unset;
        type Uri = Unset;
        type Visibility = Unset;
    }
    ///State transition - sets the `text` field to Set
    pub struct SetText<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetText<St> {}
    impl<St: State> State for SetText<St> {
        type Text = Set<members::text>;
        type Uri = St::Uri;
        type Visibility = St::Visibility;
    }
    ///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 Text = St::Text;
        type Uri = Set<members::uri>;
        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 Text = St::Text;
        type Uri = St::Uri;
        type Visibility = Set<members::visibility>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `text` field
        pub struct text(());
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `visibility` field
        pub struct visibility(());
    }
}

/// Builder for constructing an instance of this type.
pub struct StoreBuilder<St: store_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<S>, Option<AtUri<S>>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Store<S> {
    /// Create a new builder for this type
    pub fn builder() -> StoreBuilder<store_state::Empty, S> {
        StoreBuilder::builder()
    }
}

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

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

impl<St: store_state::State, S: BosStr> StoreBuilder<St, S> {
    /// Set the `additional` field (optional)
    pub fn additional(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `additional` field to an Option value (optional)
    pub fn maybe_additional(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> StoreBuilder<St, S>
where
    St: store_state::State,
    St::Text: store_state::IsUnset,
{
    /// Set the `text` field (required)
    pub fn text(
        mut self,
        value: impl Into<S>,
    ) -> StoreBuilder<store_state::SetText<St>, S> {
        self._fields.1 = Option::Some(value.into());
        StoreBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St, S: BosStr> StoreBuilder<St, S>
where
    St: store_state::State,
    St::Text: store_state::IsSet,
    St::Uri: store_state::IsSet,
    St::Visibility: store_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Store<S> {
        Store {
            additional: self._fields.0,
            text: self._fields.1.unwrap(),
            uri: self._fields.2.unwrap(),
            visibility: self._fields.3.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>>) -> Store<S> {
        Store {
            additional: self._fields.0,
            text: self._fields.1.unwrap(),
            uri: self._fields.2.unwrap(),
            visibility: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}