use serde::{Deserialize, Serialize};
use crate::types::{ChatId, InputText, Integer, ParseMode, TextEntities};
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct ReplyParameters {
message_id: Option<Integer>,
allow_sending_without_reply: Option<bool>,
chat_id: Option<ChatId>,
checklist_task_id: Option<Integer>,
ephemeral_message_id: Option<Integer>,
poll_option_id: Option<String>,
#[serde(flatten)]
quote: Option<ReplyQuote>,
}
impl ReplyParameters {
pub fn new(message_id: Integer) -> Self {
Self {
message_id: Some(message_id),
allow_sending_without_reply: None,
chat_id: None,
checklist_task_id: None,
ephemeral_message_id: None,
poll_option_id: None,
quote: None,
}
}
pub fn with_allow_sending_without_reply(mut self, value: bool) -> Self {
self.allow_sending_without_reply = Some(value);
self
}
pub fn with_chat_id<T>(mut self, value: T) -> Self
where
T: Into<ChatId>,
{
self.chat_id = Some(value.into());
self
}
pub fn with_checklist_task_id(mut self, value: Integer) -> Self {
self.checklist_task_id = Some(value);
self
}
pub fn with_ephemeral_message_id(mut self, value: Integer) -> Self {
self.ephemeral_message_id = Some(value);
self
}
pub fn with_poll_option_id<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.poll_option_id = Some(value.into());
self
}
pub fn with_quote(mut self, value: ReplyQuote) -> Self {
self.quote = Some(value);
self
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct ReplyQuote {
#[serde(rename = "quote_position")]
position: Integer,
#[serde(flatten)]
text: ReplyQuoteText,
}
impl ReplyQuote {
pub fn new<T>(position: Integer, text: T) -> Self
where
T: Into<InputText>,
{
Self {
position,
text: ReplyQuoteText::from(text),
}
}
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
struct ReplyQuoteText {
#[serde(rename = "quote")]
data: String,
#[serde(rename = "quote_entities")]
entities: Option<TextEntities>,
#[serde(rename = "quote_parse_mode")]
parse_mode: Option<ParseMode>,
}
impl<T> From<T> for ReplyQuoteText
where
T: Into<InputText>,
{
fn from(value: T) -> Self {
let InputText {
data,
entities,
parse_mode,
} = value.into();
Self {
data,
entities,
parse_mode,
}
}
}