use crate::client::BotClient;
use crate::error::Result;
use rustigram_types::payments::StarAmount;
use rustigram_types::update::BusinessConnection;
use rustigram_types::user::ChatId;
use serde::Serialize;
use std::future::{Future, IntoFuture};
use std::pin::Pin;
#[derive(Serialize)]
struct GetBusinessConnectionParams {
business_connection_id: String,
}
pub struct GetBusinessConnection {
client: BotClient,
params: GetBusinessConnectionParams,
}
impl GetBusinessConnection {
pub(crate) fn new(client: BotClient, id: impl Into<String>) -> Self {
Self {
client,
params: GetBusinessConnectionParams {
business_connection_id: id.into(),
},
}
}
}
impl IntoFuture for GetBusinessConnection {
type Output = Result<BusinessConnection>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("getBusinessConnection", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct ReadBusinessMessageParams {
business_connection_id: String,
chat_id: ChatId,
message_id: i64,
}
pub struct ReadBusinessMessage {
client: BotClient,
params: ReadBusinessMessageParams,
}
impl ReadBusinessMessage {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
chat_id: impl Into<ChatId>,
message_id: i64,
) -> Self {
Self {
client,
params: ReadBusinessMessageParams {
business_connection_id: business_connection_id.into(),
chat_id: chat_id.into(),
message_id,
},
}
}
}
impl IntoFuture for ReadBusinessMessage {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("readBusinessMessage", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct DeleteBusinessMessagesParams {
business_connection_id: String,
message_ids: Vec<i64>,
}
pub struct DeleteBusinessMessages {
client: BotClient,
params: DeleteBusinessMessagesParams,
}
impl DeleteBusinessMessages {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
message_ids: Vec<i64>,
) -> Self {
Self {
client,
params: DeleteBusinessMessagesParams {
business_connection_id: business_connection_id.into(),
message_ids,
},
}
}
}
impl IntoFuture for DeleteBusinessMessages {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("deleteBusinessMessages", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct SetBusinessAccountNameParams {
business_connection_id: String,
first_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
last_name: Option<String>,
}
pub struct SetBusinessAccountName {
client: BotClient,
params: SetBusinessAccountNameParams,
}
impl SetBusinessAccountName {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
first_name: String,
last_name: Option<String>,
) -> Self {
Self {
client,
params: SetBusinessAccountNameParams {
business_connection_id: business_connection_id.into(),
first_name,
last_name,
},
}
}
}
impl IntoFuture for SetBusinessAccountName {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("setBusinessAccountName", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct SetBusinessAccountUsernameParams {
business_connection_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
username: Option<String>,
}
pub struct SetBusinessAccountUsername {
client: BotClient,
params: SetBusinessAccountUsernameParams,
}
impl SetBusinessAccountUsername {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
username: Option<String>,
) -> Self {
Self {
client,
params: SetBusinessAccountUsernameParams {
business_connection_id: business_connection_id.into(),
username,
},
}
}
}
impl IntoFuture for SetBusinessAccountUsername {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("setBusinessAccountUsername", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct SetBusinessAccountBioParams {
business_connection_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
bio: Option<String>,
}
pub struct SetBusinessAccountBio {
client: BotClient,
params: SetBusinessAccountBioParams,
}
impl SetBusinessAccountBio {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
bio: Option<String>,
) -> Self {
Self {
client,
params: SetBusinessAccountBioParams {
business_connection_id: business_connection_id.into(),
bio,
},
}
}
}
impl IntoFuture for SetBusinessAccountBio {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("setBusinessAccountBio", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct BizConnectionIdParams {
business_connection_id: String,
}
pub struct GetBusinessAccountStarBalance {
client: BotClient,
params: BizConnectionIdParams,
}
impl GetBusinessAccountStarBalance {
pub(crate) fn new(client: BotClient, id: impl Into<String>) -> Self {
Self {
client,
params: BizConnectionIdParams {
business_connection_id: id.into(),
},
}
}
}
impl IntoFuture for GetBusinessAccountStarBalance {
type Output = Result<StarAmount>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("getBusinessAccountStarBalance", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct TransferBusinessAccountStarsParams {
business_connection_id: String,
star_count: u64,
}
pub struct TransferBusinessAccountStars {
client: BotClient,
params: TransferBusinessAccountStarsParams,
}
impl TransferBusinessAccountStars {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
star_count: u64,
) -> Self {
Self {
client,
params: TransferBusinessAccountStarsParams {
business_connection_id: business_connection_id.into(),
star_count,
},
}
}
}
impl IntoFuture for TransferBusinessAccountStars {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("transferBusinessAccountStars", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct SetBusinessAccountProfilePhotoParams {
business_connection_id: String,
photo: serde_json::Value,
#[serde(skip_serializing_if = "Option::is_none")]
is_public: Option<bool>,
}
pub struct SetBusinessAccountProfilePhoto {
client: BotClient,
params: SetBusinessAccountProfilePhotoParams,
}
impl SetBusinessAccountProfilePhoto {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
photo: serde_json::Value,
) -> Self {
Self {
client,
params: SetBusinessAccountProfilePhotoParams {
business_connection_id: business_connection_id.into(),
photo,
is_public: None,
},
}
}
pub fn is_public(mut self, v: bool) -> Self {
self.params.is_public = Some(v);
self
}
}
impl IntoFuture for SetBusinessAccountProfilePhoto {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("setBusinessAccountProfilePhoto", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct RemoveBusinessAccountProfilePhotoParams {
business_connection_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
is_public: Option<bool>,
}
pub struct RemoveBusinessAccountProfilePhoto {
client: BotClient,
params: RemoveBusinessAccountProfilePhotoParams,
}
impl RemoveBusinessAccountProfilePhoto {
pub(crate) fn new(client: BotClient, business_connection_id: impl Into<String>) -> Self {
Self {
client,
params: RemoveBusinessAccountProfilePhotoParams {
business_connection_id: business_connection_id.into(),
is_public: None,
},
}
}
pub fn is_public(mut self, v: bool) -> Self {
self.params.is_public = Some(v);
self
}
}
impl IntoFuture for RemoveBusinessAccountProfilePhoto {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("removeBusinessAccountProfilePhoto", &self.params)
.await
})
}
}
#[derive(Serialize)]
struct SetBusinessAccountGiftSettingsParams {
business_connection_id: String,
show_gift_button: bool,
accepted_gift_types: rustigram_types::payments::AcceptedGiftTypes,
}
pub struct SetBusinessAccountGiftSettings {
client: BotClient,
params: SetBusinessAccountGiftSettingsParams,
}
impl SetBusinessAccountGiftSettings {
pub(crate) fn new(
client: BotClient,
business_connection_id: impl Into<String>,
show_gift_button: bool,
accepted_gift_types: rustigram_types::payments::AcceptedGiftTypes,
) -> Self {
Self {
client,
params: SetBusinessAccountGiftSettingsParams {
business_connection_id: business_connection_id.into(),
show_gift_button,
accepted_gift_types,
},
}
}
}
impl IntoFuture for SetBusinessAccountGiftSettings {
type Output = Result<bool>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move {
self.client
.post_json("setBusinessAccountGiftSettings", &self.params)
.await
})
}
}