#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::{RecordKey, Rkey};
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
use crate::place_stream::multistream::TargetView;
use crate::place_stream::multistream::target::Target;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PutTarget<'a> {
#[serde(borrow)]
pub multistream_target: Target<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub rkey: Option<RecordKey<Rkey<'a>>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PutTargetOutput<'a> {
#[serde(flatten)]
#[serde(borrow)]
pub value: TargetView<'a>,
}
#[open_union]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic,
IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum PutTargetError<'a> {
#[serde(rename = "InvalidTargetUrl")]
InvalidTargetUrl(Option<CowStr<'a>>),
}
impl core::fmt::Display for PutTargetError<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidTargetUrl(msg) => {
write!(f, "InvalidTargetUrl")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
pub struct PutTargetResponse;
impl jacquard_common::xrpc::XrpcResp for PutTargetResponse {
const NSID: &'static str = "place.stream.multistream.putTarget";
const ENCODING: &'static str = "application/json";
type Output<'de> = PutTargetOutput<'de>;
type Err<'de> = PutTargetError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for PutTarget<'a> {
const NSID: &'static str = "place.stream.multistream.putTarget";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = PutTargetResponse;
}
pub struct PutTargetRequest;
impl jacquard_common::xrpc::XrpcEndpoint for PutTargetRequest {
const PATH: &'static str = "/xrpc/place.stream.multistream.putTarget";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<'de> = PutTarget<'de>;
type Response = PutTargetResponse;
}
pub mod put_target_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type MultistreamTarget;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type MultistreamTarget = Unset;
}
pub struct SetMultistreamTarget<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMultistreamTarget<S> {}
impl<S: State> State for SetMultistreamTarget<S> {
type MultistreamTarget = Set<members::multistream_target>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct multistream_target(());
}
}
pub struct PutTargetBuilder<'a, S: put_target_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Target<'a>>, Option<RecordKey<Rkey<'a>>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> PutTarget<'a> {
pub fn new() -> PutTargetBuilder<'a, put_target_state::Empty> {
PutTargetBuilder::new()
}
}
impl<'a> PutTargetBuilder<'a, put_target_state::Empty> {
pub fn new() -> Self {
PutTargetBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> PutTargetBuilder<'a, S>
where
S: put_target_state::State,
S::MultistreamTarget: put_target_state::IsUnset,
{
pub fn multistream_target(
mut self,
value: impl Into<Target<'a>>,
) -> PutTargetBuilder<'a, put_target_state::SetMultistreamTarget<S>> {
self._fields.0 = Option::Some(value.into());
PutTargetBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: put_target_state::State> PutTargetBuilder<'a, S> {
pub fn rkey(mut self, value: impl Into<Option<RecordKey<Rkey<'a>>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_rkey(mut self, value: Option<RecordKey<Rkey<'a>>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> PutTargetBuilder<'a, S>
where
S: put_target_state::State,
S::MultistreamTarget: put_target_state::IsSet,
{
pub fn build(self) -> PutTarget<'a> {
PutTarget {
multistream_target: self._fields.0.unwrap(),
rkey: self._fields.1,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> PutTarget<'a> {
PutTarget {
multistream_target: self._fields.0.unwrap(),
rkey: self._fields.1,
extra_data: Some(extra_data),
}
}
}