use super::*;
use serde::ser::SerializeMap;
pub type Markup<'a> = &'a [&'a [Button<'a>]];
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize)]
#[must_use]
pub struct Button<'a> {
text: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
request_contact: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
request_localization: Option<bool>,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize)]
pub struct Keyboard<'a> {
keyboard: Markup<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
resize_keyboard: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
one_time_keyboard: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
selective: Option<bool>,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Default)]
#[must_use]
pub struct Remove {
selective: Option<bool>,
}
impl<'a> Button<'a> {
pub const fn new(text: &'a str) -> Self {
Self {
text,
request_contact: None,
request_localization: None,
}
}
pub fn request_contact(mut self, is_requested: bool) -> Self {
self.request_contact = Some(is_requested);
self
}
pub fn request_localization(mut self, is_requested: bool) -> Self {
self.request_localization = Some(is_requested);
self
}
}
impl<'a> Keyboard<'a> {
pub const fn new(keyboard: Markup<'a>) -> Self {
Self {
keyboard,
resize_keyboard: None,
one_time_keyboard: None,
selective: None,
}
}
pub fn resize_keyboard(mut self, is_resized: bool) -> Self {
self.resize_keyboard = Some(is_resized);
self
}
pub fn one_time_keyboard(mut self, is_one_time: bool) -> Self {
self.one_time_keyboard = Some(is_one_time);
self
}
pub fn selective(mut self, is_selective: bool) -> Self {
self.selective = Some(is_selective);
self
}
}
impl<'a> From<Markup<'a>> for Keyboard<'a> {
fn from(markup: Markup<'a>) -> Self {
Self::new(markup)
}
}
impl Remove {
pub const fn new() -> Self {
Self { selective: None }
}
pub fn selective(mut self, is_selective: bool) -> Self {
self.selective = Some(is_selective);
self
}
}
impl serde::Serialize for Remove {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
let len = if self.selective.is_some() { 2 } else { 1 };
let mut map = s.serialize_map(Some(len))?;
map.serialize_entry("remove_keyboard", &true)?;
if let Some(selective) = self.selective {
map.serialize_entry("selective", &selective)?;
}
map.end()
}
}