use ruststream::asyncapi::{Binding, Bindings};
use serde::Serialize;
use crate::address::Settle;
const EXTENSION: &str = "x-ruststream-amqp1";
pub(crate) const REPLY_ADDRESS_LOCATION: &str = "$message.header#/reply-to";
fn extension<T: Serialize>(body: &T) -> Bindings {
Binding::extension(EXTENSION, body)
.map(|binding| Bindings::new().with(binding))
.unwrap_or_default()
}
#[derive(Debug, Serialize)]
struct Channel<'a> {
address: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
capability: Option<&'static str>,
credit: u32,
#[serde(rename = "settleMode")]
settle_mode: &'static str,
}
#[derive(Debug, Serialize)]
struct Target<'a> {
address: &'a str,
}
#[derive(Debug, Serialize)]
struct Operation {
posting: &'static str,
}
#[derive(Debug, Serialize)]
struct Server<'a> {
#[serde(rename = "containerId")]
container_id: &'a str,
}
pub(crate) fn channel(
address: &str,
capability: Option<&'static str>,
credit: u32,
settle: Settle,
) -> Bindings {
extension(&Channel {
address,
capability,
credit,
settle_mode: match settle {
Settle::AtLeastOnce => "at-least-once",
Settle::AtMostOnce => "at-most-once",
},
})
}
pub(crate) fn target(address: &str) -> Bindings {
extension(&Target { address })
}
pub(crate) fn confirmed_posting() -> Bindings {
extension(&Operation {
posting: "confirmed",
})
}
#[cfg(feature = "transaction")]
pub(crate) fn transactional_posting() -> Bindings {
extension(&Operation {
posting: "transactional",
})
}
pub(crate) fn server(container_id: &str) -> Bindings {
extension(&Server { container_id })
}