use serde::Serialize;
use crate::{
net,
requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, LabeledPrice, Message},
Bot,
};
use std::sync::Arc;
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct SendInvoice {
#[serde(skip_serializing)]
bot: Arc<Bot>,
chat_id: i32,
title: String,
description: String,
payload: String,
provider_token: String,
start_parameter: String,
currency: String,
prices: Vec<LabeledPrice>,
provider_data: Option<String>,
photo_url: Option<String>,
photo_size: Option<i32>,
photo_width: Option<i32>,
photo_height: Option<i32>,
need_name: Option<bool>,
need_phone_number: Option<bool>,
need_email: Option<bool>,
need_shipping_address: Option<bool>,
send_phone_number_to_provider: Option<bool>,
send_email_to_provider: Option<bool>,
is_flexible: Option<bool>,
disable_notification: Option<bool>,
reply_to_message_id: Option<i32>,
reply_markup: Option<InlineKeyboardMarkup>,
}
#[async_trait::async_trait]
impl Request for SendInvoice {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
net::request_json(
self.bot.client(),
self.bot.token(),
"sendInvoice",
&self,
)
.await
}
}
impl SendInvoice {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new<T, D, Pl, Pt, S, C, Pr>(
bot: Arc<Bot>,
chat_id: i32,
title: T,
description: D,
payload: Pl,
provider_token: Pt,
start_parameter: S,
currency: C,
prices: Pr,
) -> Self
where
T: Into<String>,
D: Into<String>,
Pl: Into<String>,
Pt: Into<String>,
S: Into<String>,
C: Into<String>,
Pr: Into<Vec<LabeledPrice>>,
{
let title = title.into();
let description = description.into();
let payload = payload.into();
let provider_token = provider_token.into();
let start_parameter = start_parameter.into();
let currency = currency.into();
let prices = prices.into();
Self {
bot,
chat_id,
title,
description,
payload,
provider_token,
start_parameter,
currency,
prices,
provider_data: None,
photo_url: None,
photo_size: None,
photo_width: None,
photo_height: None,
need_name: None,
need_phone_number: None,
need_email: None,
need_shipping_address: None,
send_phone_number_to_provider: None,
send_email_to_provider: None,
is_flexible: None,
disable_notification: None,
reply_to_message_id: None,
reply_markup: None,
}
}
pub fn chat_id(mut self, val: i32) -> Self {
self.chat_id = val;
self
}
pub fn title<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.title = val.into();
self
}
pub fn description<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.description = val.into();
self
}
pub fn payload<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.payload = val.into();
self
}
pub fn provider_token<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.provider_token = val.into();
self
}
pub fn start_parameter<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.start_parameter = val.into();
self
}
pub fn currency<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.currency = val.into();
self
}
pub fn prices<T>(mut self, val: T) -> Self
where
T: Into<Vec<LabeledPrice>>,
{
self.prices = val.into();
self
}
pub fn provider_data<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.provider_data = Some(val.into());
self
}
pub fn photo_url<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.photo_url = Some(val.into());
self
}
pub fn photo_size(mut self, val: i32) -> Self {
self.photo_size = Some(val);
self
}
pub fn photo_width(mut self, val: i32) -> Self {
self.photo_width = Some(val);
self
}
pub fn photo_height(mut self, val: i32) -> Self {
self.photo_height = Some(val);
self
}
pub fn need_name(mut self, val: bool) -> Self {
self.need_name = Some(val);
self
}
pub fn need_phone_number(mut self, val: bool) -> Self {
self.need_phone_number = Some(val);
self
}
pub fn need_email(mut self, val: bool) -> Self {
self.need_email = Some(val);
self
}
pub fn need_shipping_address(mut self, val: bool) -> Self {
self.need_shipping_address = Some(val);
self
}
pub fn send_phone_number_to_provider(mut self, val: bool) -> Self {
self.send_phone_number_to_provider = Some(val);
self
}
pub fn send_email_to_provider(mut self, val: bool) -> Self {
self.send_email_to_provider = Some(val);
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_flexible(mut self, val: bool) -> Self {
self.is_flexible = Some(val);
self
}
pub fn disable_notification(mut self, val: bool) -> Self {
self.disable_notification = Some(val);
self
}
pub fn reply_to_message_id(mut self, val: i32) -> Self {
self.reply_to_message_id = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}