foundation_deployment_cloudflare 0.1.1

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

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

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

/// `AlexandriaCategories` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategories {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

/// `AlexandriaCategory` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategory {
    /// created_at property.
    pub created_at: AlexandriaCategoryCreatedAt,
    /// description property.
    pub description: AlexandriaCategoryDescription,
    /// id property.
    pub id: AlexandriaCategoryId,
    /// name property.
    pub name: AlexandriaCategoryName,
}

/// `AlexandriaCategoryCreatedAt` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryCreatedAt {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

/// `AlexandriaCategoryDescription` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryDescription {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

/// `AlexandriaCategoryId` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryId {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

/// `AlexandriaCategoryName` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCategoryName {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

/// `AlexandriaGetCategoriesResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaGetCategoriesResponse {
    /// `result` property.
    pub result: Option<Vec<AlexandriaCategory>>,
}

/// `AlexandriaGetCategoryResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaGetCategoryResponse {
    /// `result` property.
    pub result: Option<AlexandriaCategory>,
}

/// `AlexandriaMessages` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaMessages {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

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

/// Arguments for [`getCategories_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetCategoriesArgs {
    /// Path parameter: `accountId`.
    pub account_id: String,
}

/// Arguments for [`getCategoryById_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetCategoryByIdArgs {
    /// Path parameter: `accountId`.
    pub account_id: String,
    /// Path parameter: `id`.
    pub id: String,
}

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

// -----------------------------------------------------------------------------
// GET /accounts/{accountId}/resource-library/categories
// -----------------------------------------------------------------------------

/// GET /accounts/{accountId}/resource-library/categories.
///
/// 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 = get_categories_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn get_categories_request<F>(
    client: DynNetClient,
    args: &GetCategoriesArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetCategoriesResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/accounts/{}/resource-library/categories",
        args.account_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: AlexandriaGetCategoriesResponse = 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 /accounts/{accountId}/resource-library/categories/{id}
// -----------------------------------------------------------------------------

/// GET /accounts/{accountId}/resource-library/categories/{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 = get_category_by_id_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn get_category_by_id_request<F>(
    client: DynNetClient,
    args: &GetCategoryByIdArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetCategoryResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/accounts/{}/resource-library/categories/{}",
        args.account_id,
        args.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: AlexandriaGetCategoryResponse = 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 })
}