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 CollectionsResource<'a> {
pub(crate) t: &'a Transport,
}
impl CollectionsResource<'_> {
pub async fn add_post(self, id: &str, body: Option<Value>, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/collections/{}/items", encode_path(id)), &build_query(query.as_ref(), &[]), Some(body_or_empty(body))).await
}
pub async fn create(self, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, "/collections", "", Some(body_or_empty(body))).await
}
pub async fn delete(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/collections/{}", encode_path(id)), "", None).await
}
pub async fn list(self) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/collections", "", None).await
}
pub async fn remove_post(self, id: &str, body: Option<Value>, query: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/collections/{}/items", encode_path(id)), &build_query(query.as_ref(), &[]), Some(body_or_empty(body))).await
}
pub async fn update(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::PATCH, &format!("/collections/{}", encode_path(id)), "", Some(body_or_empty(body))).await
}
}