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 DeleteMessagesParams {
pub chat_id: ChatId,
pub message_ids: Vec<i64>,
}
impl_into_future!(DeleteMessagesRequest<'a>);
#[derive(Clone)]
pub struct DeleteMessagesRequest<'a> {
api: &'a API,
params: DeleteMessagesParams,
}
impl<'a> RequestT for DeleteMessagesRequest<'a> {
type ParamsType = DeleteMessagesParams;
type ReturnType = bool;
fn get_name() -> &'static str {
"deleteMessages"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> DeleteMessagesRequest<'a> {
pub fn new(
api: &'a API,
chat_id: impl Into<ChatId>,
message_ids: impl IntoIterator<Item = impl Into<i64>>,
) -> Self {
Self {
api,
params: DeleteMessagesParams {
chat_id: chat_id.into(),
message_ids: message_ids.into_iter().map(Into::into).collect(),
},
}
}
#[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 message_ids(mut self, message_ids: impl IntoIterator<Item = impl Into<i64>>) -> Self {
self.params.message_ids = message_ids.into_iter().map(Into::into).collect();
self
}
}
impl API {
pub fn delete_messages(
&self,
chat_id: impl Into<ChatId>,
message_ids: impl IntoIterator<Item = impl Into<i64>>,
) -> DeleteMessagesRequest {
DeleteMessagesRequest::new(self, chat_id, message_ids)
}
}