foundation_deployment_cloudflare 0.1.2

Cloudflare API v4 client — DNS records, zones, certificates
//! Auto-generated API module for cloudflare tenants.
//!
//! Generated by `cargo run --bin ewe_platform gen_api`.
//! DO NOT EDIT MANUALLY.
//!
//! Feature flag: `cloudflare_tenants `

#![cfg(feature = "cloudflare_tenants")]
#![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;

// =============================================================================
// TYPE DECLARATIONS
// =============================================================================

/// `OrganizationsApiAccount` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiAccount {
    /// created_on property.
    pub created_on: String,
    /// id property.
    pub id: String,
    /// name property.
    pub name: Option<String>,
    /// settings property.
    pub settings: std::collections::HashMap<String, serde_json::Value>,
    /// type property.
    #[serde(rename = "type")]
    pub r#type: String,
}

/// `OrganizationsApiTenant` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiTenant {
    /// cdate property.
    pub cdate: String,
    /// customer_id property.
    pub customer_id: Option<String>,
    /// edate property.
    pub edate: String,
    /// tenant_contacts property.
    pub tenant_contacts: std::collections::HashMap<String, serde_json::Value>,
    /// tenant_labels property.
    pub tenant_labels: Vec<String>,
    /// tenant_metadata property.
    pub tenant_metadata: std::collections::HashMap<String, serde_json::Value>,
    /// tenant_name property.
    pub tenant_name: String,
    /// tenant_network property.
    pub tenant_network: serde_json::Value,
    /// tenant_status property.
    pub tenant_status: String,
    /// tenant_tag property.
    pub tenant_tag: String,
    /// tenant_type property.
    pub tenant_type: String,
    /// tenant_units property.
    pub tenant_units: Vec<OrganizationsApiTenantUnit>,
}

/// `OrganizationsApiTenantUnit` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiTenantUnit {
    /// unit_memberships property.
    pub unit_memberships: Vec<serde_json::Value>,
    /// unit_metadata property.
    pub unit_metadata: serde_json::Value,
    /// unit_name property.
    pub unit_name: String,
    /// unit_status property.
    pub unit_status: String,
    /// unit_tag property.
    pub unit_tag: String,
}

/// `OrganizationsApiV4Message` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct OrganizationsApiV4Message {
    /// code property.
    pub code: i64,
    /// message property.
    pub message: String,
}

/// `TenantsListAccountsResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct TenantsListAccountsResponse {
    /// errors property.
    pub errors: Vec<serde_json::Value>,
    /// messages property.
    pub messages: Vec<OrganizationsApiV4Message>,
    /// result property.
    pub result: Vec<OrganizationsApiAccount>,
    /// success property.
    pub success: bool,
}

/// `TenantsRetrieveTenantResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct TenantsRetrieveTenantResponse {
    /// errors property.
    pub errors: Vec<serde_json::Value>,
    /// messages property.
    pub messages: Vec<OrganizationsApiV4Message>,
    /// result property.
    pub result: OrganizationsApiTenant,
    /// success property.
    pub success: bool,
}

/// `TenantsValidAccountTypesResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct TenantsValidAccountTypesResponse {
    /// errors property.
    pub errors: Vec<serde_json::Value>,
    /// messages property.
    pub messages: Vec<OrganizationsApiV4Message>,
    /// result property.
    pub result: Vec<String>,
    /// success property.
    pub success: bool,
}

// =============================================================================
// ARGS TYPES (per-endpoint)
// =============================================================================

/// Arguments for [`Tenants_retrieveTenant_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct TenantsRetrieveTenantArgs {
    /// Path parameter: `tenant_id`.
    pub tenant_id: String,
}

/// Arguments for [`Tenants_validAccountTypes_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct TenantsValidAccountTypesArgs {
    /// Path parameter: `tenant_id`.
    pub tenant_id: String,
}

/// Arguments for [`Tenants_listAccounts_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct TenantsListAccountsArgs {
    /// Path parameter: `tenant_id`.
    pub tenant_id: String,
}

// =============================================================================
// CLIENT FUNCTIONS (per-endpoint)
// =============================================================================

// -----------------------------------------------------------------------------
// GET /tenants/{tenant_id}
// -----------------------------------------------------------------------------

/// GET /tenants/{tenant_id}.
///
/// Takes a `DynNetClient` and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Example
///
/// ```ignore
/// let response = tenants_retrieve_tenant_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn tenants_retrieve_tenant_request<F>(
    client: DynNetClient,
    args: &TenantsRetrieveTenantArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<TenantsRetrieveTenantResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/tenants/{}",
        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: TenantsRetrieveTenantResponse = 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 })
}

// -----------------------------------------------------------------------------
// GET /tenants/{tenant_id}/account_types
// -----------------------------------------------------------------------------

/// GET /tenants/{tenant_id}/account_types.
///
/// Takes a `DynNetClient` and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Example
///
/// ```ignore
/// let response = tenants_valid_account_types_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn tenants_valid_account_types_request<F>(
    client: DynNetClient,
    args: &TenantsValidAccountTypesArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<TenantsValidAccountTypesResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/tenants/{}/account_types",
        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: TenantsValidAccountTypesResponse = 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 })
}

// -----------------------------------------------------------------------------
// GET /tenants/{tenant_id}/accounts
// -----------------------------------------------------------------------------

/// GET /tenants/{tenant_id}/accounts.
///
/// Takes a `DynNetClient` and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Example
///
/// ```ignore
/// let response = tenants_list_accounts_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn tenants_list_accounts_request<F>(
    client: DynNetClient,
    args: &TenantsListAccountsArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<TenantsListAccountsResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/tenants/{}/accounts",
        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: TenantsListAccountsResponse = 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 })
}