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 OrganizationsResource<'a> {
pub(crate) t: &'a Transport,
}
impl OrganizationsResource<'_> {
pub async fn accept_invitation(self, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, "/invitations/accept", "", Some(body_or_empty(body))).await
}
pub async fn create(self, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, "/organizations", "", Some(body_or_empty(body))).await
}
pub async fn create_invitation(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::POST, &format!("/organizations/{}/invitations", encode_path(id)), "", Some(body_or_empty(body))).await
}
pub async fn list(self) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, "/organizations", "", None).await
}
pub async fn list_invitations(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/organizations/{}/invitations", encode_path(id)), "", None).await
}
pub async fn list_members(self, id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::GET, &format!("/organizations/{}/members", encode_path(id)), "", None).await
}
pub async fn remove_member(self, id: &str, user_id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/organizations/{}/members", encode_path(id)), &build_query(None, &[("userId", user_id)]), None).await
}
pub async fn revoke_invitation(self, id: &str, invitation_id: &str) -> Result<Value, MisarDevError> {
self.t.request(Method::DELETE, &format!("/organizations/{}/invitations", encode_path(id)), &build_query(None, &[("invitationId", invitation_id)]), None).await
}
pub async fn update_member(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
self.t.request(Method::PATCH, &format!("/organizations/{}/members", encode_path(id)), "", Some(body_or_empty(body))).await
}
}