use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use crate::{
Kibana, Scope,
http::{Empty, Method},
request::endpoint,
};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Space {
pub id: String,
pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default, rename = "disabledFeatures")]
pub disabled_features: Vec<String>,
#[serde(flatten)]
pub extra: Map<String, Value>,
}
impl Space {
pub fn new(id: impl Into<String>, name: impl Into<String>) -> Self {
Self {
id: id.into(),
name: name.into(),
description: None,
disabled_features: Vec::new(),
extra: Map::new(),
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Spaces<'a>(pub(crate) &'a Kibana);
impl<'a> Spaces<'a> {
pub fn list(&self) -> ListSpaces<'a> {
ListSpaces(
self.0
.request(Method::GET, Scope::Global, &["api", "spaces", "space"]),
)
}
pub fn get(&self, id: &str) -> GetSpace<'a> {
GetSpace(
self.0
.request(Method::GET, Scope::Global, &["api", "spaces", "space", id]),
)
}
pub fn create<B: Serialize + ?Sized>(&self, space: &B) -> CreateSpace<'a> {
CreateSpace(
self.0
.request(Method::POST, Scope::Global, &["api", "spaces", "space"])
.json(space),
)
}
pub fn update<B: Serialize + ?Sized>(&self, id: &str, space: &B) -> UpdateSpace<'a> {
UpdateSpace(
self.0
.request(Method::PUT, Scope::Global, &["api", "spaces", "space", id])
.json(space)
.check_body_id(id, true),
)
}
pub fn delete(&self, id: &str) -> DeleteSpace<'a> {
DeleteSpace(self.0.request(
Method::DELETE,
Scope::Global,
&["api", "spaces", "space", id],
))
}
}
endpoint! {
ListSpaces => Vec<Space>
}
endpoint! {
GetSpace => Space
}
endpoint! {
CreateSpace => Space
}
endpoint! {
UpdateSpace => Space
}
endpoint! {
DeleteSpace => Empty
}