#![allow(clippy::doc_markdown, clippy::default_trait_access)]
#[allow(unused_imports, clippy::wildcard_imports)]
use crate::{error::Result, models::*, Configuration};
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct CustomPropertiesListCustomPropertyDefinitionsOptions {
pub entity_type: Option<CustomPropertyEntityType>,
pub include_archived: Option<bool>,
pub page: Option<i32>,
pub per_page: Option<i32>,
}
impl CustomPropertiesListCustomPropertyDefinitionsOptions {
#[must_use]
pub fn new() -> Self {
Self {
entity_type: None,
include_archived: None,
page: None,
per_page: None,
}
}
#[must_use]
pub fn entity_type(mut self, entity_type: impl Into<CustomPropertyEntityType>) -> Self {
self.entity_type = Some(entity_type.into());
self
}
#[must_use]
pub fn maybe_entity_type(mut self, entity_type: Option<CustomPropertyEntityType>) -> Self {
self.entity_type = entity_type;
self
}
#[must_use]
pub fn include_archived(mut self, include_archived: impl Into<bool>) -> Self {
self.include_archived = Some(include_archived.into());
self
}
#[must_use]
pub fn maybe_include_archived(mut self, include_archived: Option<bool>) -> Self {
self.include_archived = include_archived;
self
}
#[must_use]
pub fn page(mut self, page: impl Into<i32>) -> Self {
self.page = Some(page.into());
self
}
#[must_use]
pub fn maybe_page(mut self, page: Option<i32>) -> Self {
self.page = page;
self
}
#[must_use]
pub fn per_page(mut self, per_page: impl Into<i32>) -> Self {
self.per_page = Some(per_page.into());
self
}
#[must_use]
pub fn maybe_per_page(mut self, per_page: Option<i32>) -> Self {
self.per_page = per_page;
self
}
}
#[derive(Clone)]
pub struct CustomProperties {
cfg: std::sync::Arc<Configuration>,
options: crate::api::RequestOptions,
}
impl std::fmt::Debug for CustomProperties {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CustomProperties")
.field("options", &self.options)
.finish_non_exhaustive()
}
}
impl CustomProperties {
pub(super) fn new(cfg: std::sync::Arc<Configuration>) -> Self {
Self {
cfg,
options: crate::api::RequestOptions::default(),
}
}
#[must_use]
pub fn with_options(mut self, options: crate::api::RequestOptions) -> Self {
self.options = options;
self
}
fn list_custom_property_definitions_request(
&self,
options: impl Into<Option<CustomPropertiesListCustomPropertyDefinitionsOptions>>,
) -> crate::api::Call<crate::models::CustomPropertyDefinitionListResponse> {
let CustomPropertiesListCustomPropertyDefinitionsOptions {
entity_type,
include_archived,
page,
per_page,
} = options.into().unwrap_or_default();
crate::request::Request::new(http::Method::GET, "/api/v1/custom-property-definitions")
.with_optional_query_param("entity_type", entity_type)
.with_optional_query_param("include_archived", include_archived)
.with_optional_query_param("page", page)
.with_optional_query_param("per_page", per_page)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn list_custom_property_definitions(
&self,
options: impl Into<Option<CustomPropertiesListCustomPropertyDefinitionsOptions>>,
) -> crate::api::PageCall<
crate::models::CustomPropertyDefinitionListResponse,
crate::models::CustomPropertyDefinition,
> {
static WALK: crate::api::pagination::Walk<
CustomPropertiesListCustomPropertyDefinitionsOptions,
> = crate::api::pagination::Walk::Page {
first: 0,
get: |options| options.page.map(i64::from),
set: |options, position| options.page = i32::try_from(position).ok(),
};
let this = self.clone();
let call = move |options: CustomPropertiesListCustomPropertyDefinitionsOptions| {
this.list_custom_property_definitions_request(options)
};
crate::api::PageCall::new(
options.into().unwrap_or_default(),
WALK,
crate::api::pages::CUSTOM_PROPERTIES_LIST_CUSTOM_PROPERTY_DEFINITIONS,
call,
)
}
pub fn create_custom_property_definition(
&self,
custom_property_definition_create_request: crate::models::CustomPropertyDefinitionCreateRequest,
) -> crate::api::Call<crate::models::CustomPropertyDefinition> {
crate::request::Request::new(http::Method::POST, "/api/v1/custom-property-definitions")
.with_body_param(custom_property_definition_create_request)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn retrieve_custom_property_definition(
&self,
id: &str,
) -> crate::api::Call<crate::models::CustomPropertyDefinition> {
crate::request::Request::new(
http::Method::GET,
"/api/v1/custom-property-definitions/{id}",
)
.with_path_param("id", id)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn update_custom_property_definition(
&self,
id: &str,
custom_property_definition_update_request: crate::models::CustomPropertyDefinitionUpdateRequest,
) -> crate::api::Call<crate::models::CustomPropertyDefinition> {
crate::request::Request::new(
http::Method::PUT,
"/api/v1/custom-property-definitions/{id}",
)
.with_path_param("id", id)
.with_body_param(custom_property_definition_update_request)
.with_options(&self.options)
.json(&self.cfg)
}
pub fn archive_definition(
&self,
id: &str,
) -> crate::api::Call<crate::models::CustomPropertyDefinition> {
crate::request::Request::new(
http::Method::DELETE,
"/api/v1/custom-property-definitions/{id}",
)
.with_path_param("id", id)
.with_options(&self.options)
.json(&self.cfg)
}
}