use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API, entities::misc::chat_id::ChatId, errors::ConogramError, impl_into_future,
request::RequestT,
};
#[derive(Debug, Clone, Serialize)]
pub struct SetChatTitleParams {
pub chat_id: ChatId,
pub title: String,
}
impl_into_future!(SetChatTitleRequest<'a>);
#[derive(Clone)]
pub struct SetChatTitleRequest<'a> {
api: &'a API,
params: SetChatTitleParams,
}
impl<'a> RequestT for SetChatTitleRequest<'a> {
type ParamsType = SetChatTitleParams;
type ReturnType = bool;
fn get_name() -> &'static str {
"setChatTitle"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> SetChatTitleRequest<'a> {
pub fn new(api: &'a API, chat_id: impl Into<ChatId>, title: impl Into<String>) -> Self {
Self {
api,
params: SetChatTitleParams {
chat_id: chat_id.into(),
title: title.into(),
},
}
}
#[must_use]
pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
self.params.chat_id = chat_id.into();
self
}
#[must_use]
pub fn title(mut self, title: impl Into<String>) -> Self {
self.params.title = title.into();
self
}
}
impl API {
pub fn set_chat_title(
&self,
chat_id: impl Into<ChatId>,
title: impl Into<String>,
) -> SetChatTitleRequest {
SetChatTitleRequest::new(self, chat_id, title)
}
}