use crate::error::MisarDevError;
use crate::transport::Transport;
use crate::transport::body_or_empty;
use crate::transport::build_query;
use crate::transport::encode_path;
use reqwest::Method;
use serde_json::Value;
#[derive(Debug, Clone, Copy)]
pub struct DmResource<'a> {
pub(crate) t: &'a Transport,
}
impl DmResource<'_> {
pub async fn accept_thread(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/dm/threads/{}/accept", encode_path(id)), "", None).await
}
pub async fn create_thread(self, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, "/dm/threads", "", Some(body_or_empty(body))).await
}
pub async fn create_threads_mute(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/dm/threads/{}/mute", encode_path(id)), "", None).await
}
pub async fn decline_thread(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/dm/threads/{}/decline", encode_path(id)), "", None).await
}
pub async fn delete_threads_mute(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/dm/threads/{}/mute", encode_path(id)), "", None).await
}
pub async fn list_messages(self, id: &str, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/dm/threads/{}/messages", encode_path(id)), &build_query(query.as_ref(), &[]), None).await
}
pub async fn list_threads(self, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/dm/threads", &build_query(query.as_ref(), &[]), None).await
}
pub async fn mark_thread_read(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/dm/threads/{}/read", encode_path(id)), "", None).await
}
pub async fn send_message(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/dm/threads/{}/messages", encode_path(id)), "", Some(body_or_empty(body))).await
}
pub async fn unread_counts(self) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/dm/unread", "", None).await
}
}