#![cfg(feature = "cloudflare_entitlements")]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![allow(clippy::missing_errors_doc, clippy::doc_markdown, clippy::useless_format)]
#![allow(unused_imports)]
use foundation_netio::{DynNetClient, PreparedRequestBuilder};
use foundation_netio::shared::client::http_client::HttpClient;
use serde::{Deserialize, Serialize};
use foundation_macros::JsonHash;
use super::shared::ApiResponse;
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiBoolAllocation {
#[serde(rename = "type")]
pub r#type: String,
pub value: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiEntitlement {
pub allocation: serde_json::Value,
pub feature: OrganizationsApiFeature,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiFeature {
pub key: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiInnateEntitlements {
pub allow_add_subdomain: OrganizationsApiBoolAllocation,
pub allow_auto_accept_invites: OrganizationsApiBoolAllocation,
pub cname_setup_allowed: OrganizationsApiBoolAllocation,
pub custom_entitlements: Option<Vec<OrganizationsApiEntitlement>>,
pub mhs_certificate_count: OrganizationsApiMaxCountAllocation,
pub partial_setup_allowed: OrganizationsApiBoolAllocation,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiMaxCountAllocation {
#[serde(rename = "type")]
pub r#type: String,
pub value: i64,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiV4Message {
pub code: i64,
pub message: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct TenantsListEntitlementsResponse {
pub errors: Vec<serde_json::Value>,
pub messages: Vec<OrganizationsApiV4Message>,
pub result: OrganizationsApiInnateEntitlements,
pub success: bool,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct TenantsListEntitlementsArgs {
pub tenant_id: String,
}
pub async fn tenants_list_entitlements_request<F>(
client: DynNetClient,
args: &TenantsListEntitlementsArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<TenantsListEntitlementsResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/tenants/{}/entitlements",
args.tenant_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: TenantsListEntitlementsResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}