use crate::{
model::forum::ForumPosts,
request::{Query, Request},
routing::Route,
Osu,
};
use serde::Serialize;
#[must_use = "requests must be configured and executed"]
#[derive(Serialize)]
pub struct GetForumPosts<'a> {
#[serde(skip)]
osu: &'a Osu,
#[serde(skip)]
topic_id: u64,
sort: Option<&'static str>,
limit: Option<usize>,
start: Option<u64>,
end: Option<u64>,
#[serde(rename = "cursor_string")]
cursor: Option<&'a str>,
}
impl<'a> GetForumPosts<'a> {
pub(crate) const fn new(osu: &'a Osu, topic_id: u64) -> Self {
Self {
osu,
topic_id,
sort: None,
limit: None,
start: None,
end: None,
cursor: None,
}
}
#[inline]
pub fn limit(mut self, limit: usize) -> Self {
self.limit = Some(limit.min(50));
self
}
#[inline]
pub const fn sort_ascending(mut self) -> Self {
self.sort = Some("id_asc");
self
}
#[inline]
pub const fn sort_descending(mut self) -> Self {
self.sort = Some("id_desc");
self
}
#[inline]
pub const fn start_id(mut self, start: u64) -> Self {
self.start = Some(start);
self
}
#[inline]
pub const fn end_id(mut self, end: u64) -> Self {
self.end = Some(end);
self
}
#[inline]
pub const fn cursor(mut self, cursor: &'a str) -> Self {
self.cursor = Some(cursor);
self
}
}
into_future! {
|self: GetForumPosts<'_>| -> ForumPosts {
Request::with_query(
Route::GetForumPosts { topic_id: self.topic_id },
Query::encode(&self),
)
}
}