#![allow(clippy::too_many_arguments)]
use serde::Serialize;
use crate::error::Result;
use crate::input_file::InputFile;
use crate::Bot;
use std::collections::HashMap;
impl Bot {
pub fn set_chat_photo<F: InputFile>(&self, chat_id: i64, photo: F) -> SetChatPhotoBuilder<F> {
SetChatPhotoBuilder::new(self, chat_id, photo)
}
}
#[derive(Serialize)]
pub struct SetChatPhotoBuilder<'a, F: InputFile> {
#[serde(skip)]
bot: &'a Bot,
#[serde(skip)]
data: HashMap<&'a str, F>,
pub chat_id: i64,
}
impl<'a, F: InputFile> SetChatPhotoBuilder<'a, F> {
pub fn new(bot: &'a Bot, chat_id: i64, photo: F) -> Self {
let mut data = HashMap::new();
data.insert("photo", photo);
Self { bot, data, chat_id }
}
pub fn chat_id(mut self, chat_id: i64) -> Self {
self.chat_id = chat_id;
self
}
pub fn photo(mut self, photo: F) -> Self {
self.data.insert("photo", photo);
self
}
pub async fn send(self) -> Result<bool> {
let form = serde_json::to_value(&self)?;
self.bot
.post("setChatPhoto", Some(&form), Some(self.data))
.await
}
}