use derive_builder::Builder;
use crate::{
core::Serialize,
dx::pubnub_client::PubNubClientInstance,
lib::{alloc::string::String, collections::HashMap},
};
pub struct PublishMessageBuilder<T, M, D>
where
M: Serialize,
{
pub(super) pub_nub_client: PubNubClientInstance<T, D>,
pub(super) message: M,
pub(super) seqn: u16,
}
impl<T, M, D> PublishMessageBuilder<T, M, D>
where
M: Serialize,
{
pub fn channel<S>(self, channel: S) -> PublishMessageViaChannelBuilder<T, M, D>
where
S: Into<String>,
{
PublishMessageViaChannelBuilder::<T, M, D> {
pub_nub_client: Some(self.pub_nub_client),
seqn: Some(self.seqn),
..Default::default()
}
.message(self.message)
.channel(channel.into())
}
}
#[derive(Builder)]
#[builder(pattern = "owned", build_fn(vis = "pub(super)"))]
#[cfg_attr(not(feature = "std"), builder(no_std))]
pub struct PublishMessageViaChannel<T, M, D>
where
M: Serialize,
{
#[builder(setter(custom))]
pub(super) pub_nub_client: PubNubClientInstance<T, D>,
#[builder(setter(custom))]
pub(super) seqn: u16,
pub(super) message: M,
#[builder(setter(into))]
pub(super) channel: String,
#[builder(setter(strip_option), default = "None")]
pub(super) store: Option<bool>,
#[builder(default = "true")]
pub(super) replicate: bool,
#[builder(setter(strip_option), default = "None")]
pub(super) ttl: Option<u32>,
#[builder(setter(strip_option), default = "false")]
pub(super) use_post: bool,
#[builder(setter(strip_option), default = "None")]
pub(super) meta: Option<HashMap<String, String>>,
#[builder(setter(strip_option, into), default = "None")]
pub(super) space_id: Option<String>,
#[builder(setter(strip_option, into), default = "None")]
pub(super) r#type: Option<String>,
}