1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::base::{Request, TelegramMethod};

use crate::{client::Bot, types::MenuButton};

use serde::Serialize;
use serde_with::skip_serializing_none;

/// Use this method to change the bot's menu button in a private chat, or the default menu button.
/// # Documentation
/// <https://core.telegram.org/bots/api#setchatmenubutton>
/// # Returns
/// Returns `True` on success
#[skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)]
pub struct SetChatMenuButton {
    /// Unique identifier for the target private chat. If not specified, default bot's menu button will be changed.
    pub chat_id: i64,
    /// A JSON-serialized object for the bot's new menu button. Defaults to [`MenuButtonDefault`](crate::types::MenuButtonDefault).
    pub menu_button: Option<MenuButton>,
}

impl SetChatMenuButton {
    #[must_use]
    pub fn new(chat_id: i64) -> Self {
        Self {
            chat_id,
            menu_button: None,
        }
    }

    #[must_use]
    pub fn chat_id(self, val: i64) -> Self {
        Self {
            chat_id: val,
            ..self
        }
    }

    #[must_use]
    pub fn menu_button(self, val: impl Into<MenuButton>) -> Self {
        Self {
            menu_button: Some(val.into()),
            ..self
        }
    }
}

impl SetChatMenuButton {
    #[must_use]
    pub fn menu_button_option(self, val: Option<impl Into<MenuButton>>) -> Self {
        Self {
            menu_button: val.map(Into::into),
            ..self
        }
    }
}

impl TelegramMethod for SetChatMenuButton {
    type Method = Self;
    type Return = bool;

    fn build_request<Client>(&self, _bot: &Bot<Client>) -> Request<Self::Method> {
        Request::new("setChatMenuButton", self, None)
    }
}