use crate::{
model::comments::{CommentBundle, CommentSort},
request::{serialize::maybe_comment_sort, Query, Request},
routing::Route,
Osu,
};
use serde::Serialize;
#[must_use = "requests must be configured and executed"]
#[derive(Serialize)]
pub struct GetComments<'a> {
#[serde(skip)]
osu: &'a Osu,
commentable_type: Option<String>,
commentable_id: Option<u32>,
parent_id: Option<u32>,
#[serde(serialize_with = "maybe_comment_sort")]
sort: Option<CommentSort>,
#[serde(rename = "cursor_string")]
cursor: Option<&'a str>,
}
impl<'a> GetComments<'a> {
pub(crate) const fn new(osu: &'a Osu) -> Self {
Self {
osu,
commentable_type: None,
commentable_id: None,
parent_id: None,
sort: None,
cursor: None,
}
}
#[inline]
pub const fn sort_new(mut self) -> Self {
self.sort = Some(CommentSort::New);
self
}
#[inline]
pub const fn sort_top(mut self) -> Self {
self.sort = Some(CommentSort::Top);
self
}
#[inline]
pub const fn sort_old(mut self) -> Self {
self.sort = Some(CommentSort::Old);
self
}
#[inline]
pub const fn parent(mut self, parent_id: u32) -> Self {
self.parent_id = Some(parent_id);
self
}
#[inline]
pub const fn commentable_id(mut self, commentable_id: u32) -> Self {
self.commentable_id = Some(commentable_id);
self
}
#[inline]
pub fn commentable_type(mut self, commentable_type: impl Into<String>) -> Self {
self.commentable_type = Some(commentable_type.into());
self
}
#[inline]
pub(crate) const fn cursor(mut self, cursor: &'a str) -> Self {
self.cursor = Some(cursor);
self
}
}
into_future! {
|self: GetComments<'_>| -> CommentBundle {
Request::with_query(Route::GetComments, Query::encode(&self))
}
}