use super::send_method;
use crate::{
connectors::Connector, errors, internal::Client, token, types::inline_query,
};
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
#[must_use = "methods do nothing unless turned into a future"]
pub struct AnswerInlineQuery<'a, C> {
#[serde(skip)]
client: &'a Client<C>,
#[serde(skip)]
token: token::Ref<'a>,
inline_query_id: inline_query::id::Ref<'a>,
results: &'a [inline_query::Result<'a>],
#[serde(skip_serializing_if = "Option::is_none")]
cache_time: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
is_personal: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
next_offset: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
switch_pm_text: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
switch_pm_parameter: Option<&'a str>,
}
impl<'a, C> AnswerInlineQuery<'a, C> {
pub(crate) const fn new(
client: &'a Client<C>,
token: token::Ref<'a>,
inline_query_id: inline_query::id::Ref<'a>,
results: &'a [inline_query::Result<'a>],
) -> Self {
Self {
client,
token,
inline_query_id,
results,
cache_time: None,
is_personal: None,
next_offset: None,
switch_pm_text: None,
switch_pm_parameter: None,
}
}
pub fn cache_time(mut self, time: u64) -> Self {
self.cache_time = Some(time);
self
}
pub fn personal(mut self, is_personal: bool) -> Self {
self.is_personal = Some(is_personal);
self
}
pub fn next_offset(mut self, offset: &'a str) -> Self {
self.next_offset = Some(offset);
self
}
pub fn switch_pm(mut self, text: &'a str, parameter: &'a str) -> Self {
self.switch_pm_text = Some(text);
self.switch_pm_parameter = Some(parameter);
self
}
}
impl<C: Connector> AnswerInlineQuery<'_, C> {
pub async fn call(self) -> Result<(), errors::MethodCall> {
send_method::<bool, _>(
self.client,
self.token,
"answerInlineQuery",
None,
serde_json::to_vec(&self).unwrap(),
)
.await?;
Ok(())
}
}