#![allow(missing_docs, unreachable_pub, clippy::all, clippy::pedantic)]
use crate::client::Client;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetTopicEntriesParams {
pub page: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetEverythingTopicsParams {
pub page: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetSentTopicsParams {
pub page: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetSpamTopicsParams {
pub page: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetTrashTopicsParams {
pub page: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct TrashTopicParams {
pub confirm_destroy: Option<String>,
}
pub struct Topics<'a> {
client: &'a Client,
}
impl<'a> Topics<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
pub fn client(&self) -> &'a Client {
self.client
}
pub async fn empty_spam(&self) -> Result<(), Error> {
let operation = self.client.operation(&routes::EMPTY_SPAM, &[]);
self.client.send_unit(operation).await
}
pub async fn empty_trash(&self) -> Result<(), Error> {
let operation = self.client.operation(&routes::EMPTY_TRASH, &[]);
self.client.send_unit(operation).await
}
pub async fn get(&self, topic_id: i64) -> Result<GetTopicResponseContent, Error> {
let mut operation = self.client.operation(&routes::GET_TOPIC, &[&topic_id]);
operation.resource_id(topic_id);
self.client.send(operation).await
}
pub async fn get_entries(
&self,
topic_id: i64,
params: &GetTopicEntriesParams,
) -> Result<Page<GetTopicEntriesResponseContent>, Error> {
let mut operation = self
.client
.operation(&routes::GET_TOPIC_ENTRIES, &[&topic_id]);
operation.resource_id(topic_id);
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn get_everything(
&self,
params: &GetEverythingTopicsParams,
) -> Result<Page<GetEverythingTopicsResponseContent>, Error> {
let mut operation = self.client.operation(&routes::GET_EVERYTHING_TOPICS, &[]);
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn get_sent(
&self,
params: &GetSentTopicsParams,
) -> Result<Page<GetSentTopicsResponseContent>, Error> {
let mut operation = self.client.operation(&routes::GET_SENT_TOPICS, &[]);
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn get_spam(
&self,
params: &GetSpamTopicsParams,
) -> Result<Page<GetSpamTopicsResponseContent>, Error> {
let mut operation = self.client.operation(&routes::GET_SPAM_TOPICS, &[]);
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn get_trash(
&self,
params: &GetTrashTopicsParams,
) -> Result<Page<GetTrashTopicsResponseContent>, Error> {
let mut operation = self.client.operation(&routes::GET_TRASH_TOPICS, &[]);
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
pub async fn mark_ham(&self, topic_id: i64) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::MARK_TOPIC_HAM, &[&topic_id]);
operation.resource_id(topic_id);
self.client.send_unit(operation).await
}
pub async fn move_topic(
&self,
topic_id: i64,
body: &MoveTopicRequestContent,
) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::MOVE_TOPIC, &[&topic_id]);
operation.resource_id(topic_id);
operation.json(body)?;
self.client.send_unit(operation).await
}
pub async fn restore(&self, topic_id: i64) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::RESTORE_TOPIC, &[&topic_id]);
operation.resource_id(topic_id);
self.client.send_unit(operation).await
}
pub async fn trash(&self, topic_id: i64, params: &TrashTopicParams) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::TRASH_TOPIC, &[&topic_id]);
operation.resource_id(topic_id);
operation.query_optional("confirm_destroy", params.confirm_destroy.as_ref());
self.client.send_unit(operation).await
}
}