jacquard-api 0.11.0

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: ooo.bsky.authfetch.putRecord
//
// 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::types::string::{AtUri, Nsid, RecordKey, Rkey};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::ooo_bsky::authfetch::strategy::Strategy;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PutRecord<'a> {
    ///The NSID of the record collection.
    #[serde(borrow)]
    pub collection: Nsid<'a>,
    ///The private record value to store.
    #[serde(borrow)]
    pub record: Data<'a>,
    ///The Record Key.
    #[serde(borrow)]
    pub rkey: RecordKey<Rkey<'a>>,
    ///The strategy used to authenticate fetch requests for this record.
    #[serde(borrow)]
    pub strategy: Strategy<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PutRecordOutput<'a> {
    ///The AT URI of the stored record.
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}

/// Response type for ooo.bsky.authfetch.putRecord
pub struct PutRecordResponse;
impl jacquard_common::xrpc::XrpcResp for PutRecordResponse {
    const NSID: &'static str = "ooo.bsky.authfetch.putRecord";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = PutRecordOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for PutRecord<'a> {
    const NSID: &'static str = "ooo.bsky.authfetch.putRecord";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = PutRecordResponse;
}

/// Endpoint type for ooo.bsky.authfetch.putRecord
pub struct PutRecordRequest;
impl jacquard_common::xrpc::XrpcEndpoint for PutRecordRequest {
    const PATH: &'static str = "/xrpc/ooo.bsky.authfetch.putRecord";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = PutRecord<'de>;
    type Response = PutRecordResponse;
}

pub mod put_record_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 Rkey;
        type Collection;
        type Strategy;
        type Record;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Rkey = Unset;
        type Collection = Unset;
        type Strategy = Unset;
        type Record = Unset;
    }
    ///State transition - sets the `rkey` field to Set
    pub struct SetRkey<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRkey<S> {}
    impl<S: State> State for SetRkey<S> {
        type Rkey = Set<members::rkey>;
        type Collection = S::Collection;
        type Strategy = S::Strategy;
        type Record = S::Record;
    }
    ///State transition - sets the `collection` field to Set
    pub struct SetCollection<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCollection<S> {}
    impl<S: State> State for SetCollection<S> {
        type Rkey = S::Rkey;
        type Collection = Set<members::collection>;
        type Strategy = S::Strategy;
        type Record = S::Record;
    }
    ///State transition - sets the `strategy` field to Set
    pub struct SetStrategy<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStrategy<S> {}
    impl<S: State> State for SetStrategy<S> {
        type Rkey = S::Rkey;
        type Collection = S::Collection;
        type Strategy = Set<members::strategy>;
        type Record = S::Record;
    }
    ///State transition - sets the `record` field to Set
    pub struct SetRecord<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecord<S> {}
    impl<S: State> State for SetRecord<S> {
        type Rkey = S::Rkey;
        type Collection = S::Collection;
        type Strategy = S::Strategy;
        type Record = Set<members::record>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `rkey` field
        pub struct rkey(());
        ///Marker type for the `collection` field
        pub struct collection(());
        ///Marker type for the `strategy` field
        pub struct strategy(());
        ///Marker type for the `record` field
        pub struct record(());
    }
}

/// Builder for constructing an instance of this type
pub struct PutRecordBuilder<'a, S: put_record_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Nsid<'a>>,
        Option<Data<'a>>,
        Option<RecordKey<Rkey<'a>>>,
        Option<Strategy<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> PutRecord<'a> {
    /// Create a new builder for this type
    pub fn new() -> PutRecordBuilder<'a, put_record_state::Empty> {
        PutRecordBuilder::new()
    }
}

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

impl<'a, S> PutRecordBuilder<'a, S>
where
    S: put_record_state::State,
    S::Collection: put_record_state::IsUnset,
{
    /// Set the `collection` field (required)
    pub fn collection(
        mut self,
        value: impl Into<Nsid<'a>>,
    ) -> PutRecordBuilder<'a, put_record_state::SetCollection<S>> {
        self._fields.0 = Option::Some(value.into());
        PutRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PutRecordBuilder<'a, S>
where
    S: put_record_state::State,
    S::Record: put_record_state::IsUnset,
{
    /// Set the `record` field (required)
    pub fn record(
        mut self,
        value: impl Into<Data<'a>>,
    ) -> PutRecordBuilder<'a, put_record_state::SetRecord<S>> {
        self._fields.1 = Option::Some(value.into());
        PutRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PutRecordBuilder<'a, S>
where
    S: put_record_state::State,
    S::Rkey: put_record_state::IsUnset,
{
    /// Set the `rkey` field (required)
    pub fn rkey(
        mut self,
        value: impl Into<RecordKey<Rkey<'a>>>,
    ) -> PutRecordBuilder<'a, put_record_state::SetRkey<S>> {
        self._fields.2 = Option::Some(value.into());
        PutRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PutRecordBuilder<'a, S>
where
    S: put_record_state::State,
    S::Strategy: put_record_state::IsUnset,
{
    /// Set the `strategy` field (required)
    pub fn strategy(
        mut self,
        value: impl Into<Strategy<'a>>,
    ) -> PutRecordBuilder<'a, put_record_state::SetStrategy<S>> {
        self._fields.3 = Option::Some(value.into());
        PutRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PutRecordBuilder<'a, S>
where
    S: put_record_state::State,
    S::Rkey: put_record_state::IsSet,
    S::Collection: put_record_state::IsSet,
    S::Strategy: put_record_state::IsSet,
    S::Record: put_record_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> PutRecord<'a> {
        PutRecord {
            collection: self._fields.0.unwrap(),
            record: self._fields.1.unwrap(),
            rkey: self._fields.2.unwrap(),
            strategy: 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, Data<'a>>,
    ) -> PutRecord<'a> {
        PutRecord {
            collection: self._fields.0.unwrap(),
            record: self._fields.1.unwrap(),
            rkey: self._fields.2.unwrap(),
            strategy: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}