foundation_deployment_cloudflare 0.1.1

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

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

/// `AbuseReportsEmailListItem` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsEmailListItem {
    /// body property.
    pub body: String,
    /// id property.
    pub id: String,
    /// recipient property.
    pub recipient: String,
    /// sent_at property.
    pub sent_at: String,
    /// subject property.
    pub subject: String,
}

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

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

/// `AbuseReportsMitigationListItem` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigationListItem {
    /// effective_date property.
    pub effective_date: String,
    /// entity_id property.
    pub entity_id: String,
    /// entity_type property.
    pub entity_type: AbuseReportsMitigatedEntityType,
    /// id property.
    pub id: String,
    /// status property.
    pub status: AbuseReportsMitigationStatus,
    /// type property.
    #[serde(rename = "type")]
    pub r#type: AbuseReportsMitigationType,
}

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

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

/// `ListEmailsResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListEmailsResponse {
    /// errors property.
    pub errors: Option<Vec<AbuseReportsMessage>>,
    /// messages property.
    pub messages: Option<Vec<AbuseReportsMessage>>,
    /// result property.
    pub result: Option<ListEmailsResponseResult>,
    /// result_info property.
    pub result_info: Option<ListEmailsResponseResultInfo>,
    /// success property.
    pub success: bool,
}

/// `ListEmailsResponseResult` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListEmailsResponseResult {
    /// emails property.
    pub emails: Vec<AbuseReportsEmailListItem>,
}

/// `ListEmailsResponseResultInfo` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListEmailsResponseResultInfo {
    /// count property.
    pub count: f64,
    /// page property.
    pub page: f64,
    /// per_page property.
    pub per_page: f64,
    /// total_count property.
    pub total_count: f64,
    /// total_pages property.
    pub total_pages: f64,
}

/// `ListMitigationsResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListMitigationsResponse {
    /// errors property.
    pub errors: Option<Vec<AbuseReportsMessage>>,
    /// messages property.
    pub messages: Option<Vec<AbuseReportsMessage>>,
    /// result property.
    pub result: Option<ListMitigationsResponseResult>,
    /// result_info property.
    pub result_info: Option<ListMitigationsResponseResultInfo>,
    /// success property.
    pub success: bool,
}

/// `ListMitigationsResponseResult` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListMitigationsResponseResult {
    /// mitigations property.
    pub mitigations: Vec<AbuseReportsMitigationListItem>,
}

/// `ListMitigationsResponseResultInfo` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListMitigationsResponseResultInfo {
    /// count property.
    pub count: f64,
    /// page property.
    pub page: f64,
    /// per_page property.
    pub per_page: f64,
    /// total_count property.
    pub total_count: f64,
    /// total_pages property.
    pub total_pages: f64,
}

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

/// Arguments for [`ListEmails_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct ListEmailsArgs {
    /// Path parameter: `account_id`.
    pub account_id: String,
    /// Path parameter: `report_id`.
    pub report_id: String,
    /// Query parameter: `page`.
    pub page: Option<String>,
    /// Query parameter: `per_page`.
    pub per_page: Option<String>,
}

/// Arguments for [`ListMitigations_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct ListMitigationsArgs {
    /// Path parameter: `account_id`.
    pub account_id: String,
    /// Path parameter: `report_id`.
    pub report_id: String,
    /// Query parameter: `page`.
    pub page: Option<String>,
    /// Query parameter: `per_page`.
    pub per_page: Option<String>,
    /// Query parameter: `sort`.
    pub sort: Option<String>,
    /// Query parameter: `type`.
    pub r#type: Option<String>,
    /// Query parameter: `effective_before`.
    pub effective_before: Option<String>,
    /// Query parameter: `effective_after`.
    pub effective_after: Option<String>,
    /// Query parameter: `status`.
    pub status: Option<String>,
    /// Query parameter: `entity_type`.
    pub entity_type: Option<String>,
}

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

// -----------------------------------------------------------------------------
// GET /accounts/{account_id}/abuse-reports/{report_id}/emails
// -----------------------------------------------------------------------------

/// GET /accounts/{account_id}/abuse-reports/{report_id}/emails.
///
/// 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 = list_emails_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn list_emails_request<F>(
    client: DynNetClient,
    args: &ListEmailsArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<ListEmailsResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/accounts/{}/abuse-reports/{}/emails",
        args.account_id,
        args.report_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()))?;

    builder = builder.query("page", args.page.as_deref());
    builder = builder.query("per_page", args.per_page.as_deref());

    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: ListEmailsResponse = 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/{account_id}/abuse-reports/{report_id}/mitigations
// -----------------------------------------------------------------------------

/// GET /accounts/{account_id}/abuse-reports/{report_id}/mitigations.
///
/// 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 = list_mitigations_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn list_mitigations_request<F>(
    client: DynNetClient,
    args: &ListMitigationsArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<ListMitigationsResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/accounts/{}/abuse-reports/{}/mitigations",
        args.account_id,
        args.report_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()))?;

    builder = builder.query("page", args.page.as_deref());
    builder = builder.query("per_page", args.per_page.as_deref());
    builder = builder.query("sort", args.sort.as_deref());
    builder = builder.query("type", args.r#type.as_deref());
    builder = builder.query("effective_before", args.effective_before.as_deref());
    builder = builder.query("effective_after", args.effective_after.as_deref());
    builder = builder.query("status", args.status.as_deref());
    builder = builder.query("entity_type", args.entity_type.as_deref());

    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: ListMitigationsResponse = 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 })
}