jacquard-api 0.11.0

Generated AT Protocol API bindings for Jacquard
Documentation
// @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;
use jacquard_common::types::string::AtUri;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Store<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub additional: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub text: CowStr<'a>,
    ///The URI must include the logged-in user's DID in the format at://did...
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub visibility: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct StoreOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub message: Option<CowStr<'a>>,
    pub success: bool,
}

/// Response type for uk.skyblur.post.store
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<'de> = StoreOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for Store<'a> {
    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 type for uk.skyblur.post.store
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<'de> = Store<'de>;
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetText<S> {}
    impl<S: State> State for SetText<S> {
        type Text = Set<members::text>;
        type Uri = S::Uri;
        type Visibility = S::Visibility;
    }
    ///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 Text = S::Text;
        type Uri = Set<members::uri>;
        type Visibility = S::Visibility;
    }
    ///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 Text = S::Text;
        type Uri = S::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<'a, S: store_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<AtUri<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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