/*
 * Svix API
 *
 * Welcome to the Svix API documentation!  Useful links: [Homepage](https://www.svix.com) | [Support email](mailto:support+docs@svix.com) | [Blog](https://www.svix.com/blog/) | [Slack Community](https://www.svix.com/slack/)  # Introduction  This is the reference documentation and schemas for the [Svix webhook service](https://www.svix.com) API. For tutorials and other documentation please refer to [the documentation](https://docs.svix.com).  ## Main concepts  In Svix you have four important entities you will be interacting with:  - `messages`: these are the webhooks being sent. They can have contents and a few other properties. - `application`: this is where `messages` are sent to. Usually you want to create one application for each user on your platform. - `endpoint`: endpoints are the URLs messages will be sent to. Each application can have multiple `endpoints` and each message sent to that application will be sent to all of them (unless they are not subscribed to the sent event type). - `event-type`: event types are identifiers denoting the type of the message being sent. Event types are primarily used to decide which events are sent to which endpoint.   ## Authentication  Get your authentication token (`AUTH_TOKEN`) from the [Svix dashboard](https://dashboard.svix.com) and use it as part of the `Authorization` header as such: `Authorization: Bearer ${AUTH_TOKEN}`.  <SecurityDefinitions />   ## Code samples  The code samples assume you already have the respective libraries installed and you know how to use them. For the latest information on how to do that, please refer to [the documentation](https://docs.svix.com/).   ## Idempotency  Svix supports [idempotency](https://en.wikipedia.org/wiki/Idempotence) for safely retrying requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit and you do not receive a response.  To perform an idempotent request, pass the idempotency key in the `Idempotency-Key` header to the request. The idempotency key should be a unique value generated by the client. You can create the key in however way you like, though we suggest using UUID v4, or any other string with enough entropy to avoid collisions.  Svix's idempotency works by saving the resulting status code and body of the first request made for any given idempotency key for any successful request. Subsequent requests with the same key return the same result.  Please note that idempotency is only supported for `POST` requests.   ## Cross-Origin Resource Sharing  This API features Cross-Origin Resource Sharing (CORS) implemented in compliance with [W3C spec](https://www.w3.org/TR/cors/). And that allows cross-domain communication from the browser. All responses have a wildcard same-origin which makes them completely public and accessible to everyone, including any code on any site. 
 *
 * The version of the OpenAPI document: 1.4
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;

use crate::apis::ResponseContent;
use super::{Error, configuration};

/// struct for passing parameters to the method `get_attempt_api_v1_app_app_id_msg_msg_id_attempt_attempt_id_get`
#[derive(Clone, Debug)]
pub struct GetAttemptApiV1AppAppIdMsgMsgIdAttemptAttemptIdGetParams {
    pub attempt_id: String,
    pub msg_id: String,
    pub app_id: String,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `get_attempt_headers_api_v1_app_app_id_msg_msg_id_attempt_attempt_id_headers_get`
#[derive(Clone, Debug)]
pub struct GetAttemptHeadersApiV1AppAppIdMsgMsgIdAttemptAttemptIdHeadersGetParams {
    pub app_id: String,
    pub msg_id: String,
    pub attempt_id: String,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `list_attempted_destinations_api_v1_app_app_id_msg_msg_id_endpoint_get`
#[derive(Clone, Debug)]
pub struct ListAttemptedDestinationsApiV1AppAppIdMsgMsgIdEndpointGetParams {
    pub msg_id: String,
    pub app_id: String,
    pub iterator: Option<String>,
    pub limit: Option<i32>,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `list_attempted_messages_api_v1_app_app_id_endpoint_endpoint_id_msg_get`
#[derive(Clone, Debug)]
pub struct ListAttemptedMessagesApiV1AppAppIdEndpointEndpointIdMsgGetParams {
    pub endpoint_id: String,
    pub app_id: String,
    pub iterator: Option<String>,
    pub limit: Option<i32>,
    pub channel: Option<String>,
    pub status: Option<crate::models::MessageStatus>,
    pub before: Option<String>,
    pub after: Option<String>,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `list_attempts_api_v1_app_app_id_msg_msg_id_attempt_get`
#[derive(Clone, Debug)]
pub struct ListAttemptsApiV1AppAppIdMsgMsgIdAttemptGetParams {
    pub app_id: String,
    pub msg_id: String,
    pub iterator: Option<String>,
    pub limit: Option<i32>,
    pub endpoint_id: Option<String>,
    pub event_types: Option<Vec<String>>,
    pub channel: Option<String>,
    pub status: Option<crate::models::MessageStatus>,
    pub before: Option<String>,
    pub after: Option<String>,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `list_attempts_by_endpoint_api_v1_app_app_id_attempt_endpoint_endpoint_id_get`
#[derive(Clone, Debug)]
pub struct ListAttemptsByEndpointApiV1AppAppIdAttemptEndpointEndpointIdGetParams {
    pub app_id: String,
    pub endpoint_id: String,
    pub iterator: Option<String>,
    pub limit: Option<i32>,
    pub status: Option<crate::models::MessageStatus>,
    pub status_code_class: Option<crate::models::StatusCodeClass>,
    pub event_types: Option<Vec<String>>,
    pub channel: Option<String>,
    pub before: Option<String>,
    pub after: Option<String>,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `list_attempts_by_msg_api_v1_app_app_id_attempt_msg_msg_id_get`
#[derive(Clone, Debug)]
pub struct ListAttemptsByMsgApiV1AppAppIdAttemptMsgMsgIdGetParams {
    pub app_id: String,
    pub msg_id: String,
    pub endpoint_id: Option<String>,
    pub iterator: Option<String>,
    pub limit: Option<i32>,
    pub status: Option<crate::models::MessageStatus>,
    pub status_code_class: Option<crate::models::StatusCodeClass>,
    pub event_types: Option<Vec<String>>,
    pub channel: Option<String>,
    pub before: Option<String>,
    pub after: Option<String>,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `list_attempts_for_endpoint_api_v1_app_app_id_msg_msg_id_endpoint_endpoint_id_attempt_get`
#[derive(Clone, Debug)]
pub struct ListAttemptsForEndpointApiV1AppAppIdMsgMsgIdEndpointEndpointIdAttemptGetParams {
    pub msg_id: String,
    pub app_id: String,
    pub endpoint_id: String,
    pub iterator: Option<String>,
    pub limit: Option<i32>,
    pub event_types: Option<Vec<String>>,
    pub channel: Option<String>,
    pub status: Option<crate::models::MessageStatus>,
    pub before: Option<String>,
    pub after: Option<String>,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}

/// struct for passing parameters to the method `resend_webhook_api_v1_app_app_id_msg_msg_id_endpoint_endpoint_id_resend_post`
#[derive(Clone, Debug)]
pub struct ResendWebhookApiV1AppAppIdMsgMsgIdEndpointEndpointIdResendPostParams {
    pub endpoint_id: String,
    pub msg_id: String,
    pub app_id: String,
    /// The request's idempotency key
    pub idempotency_key: Option<String>
}


/// struct for typed errors of method `get_attempt_api_v1_app_app_id_msg_msg_id_attempt_attempt_id_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAttemptApiV1AppAppIdMsgMsgIdAttemptAttemptIdGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `get_attempt_headers_api_v1_app_app_id_msg_msg_id_attempt_attempt_id_headers_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAttemptHeadersApiV1AppAppIdMsgMsgIdAttemptAttemptIdHeadersGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `list_attempted_destinations_api_v1_app_app_id_msg_msg_id_endpoint_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAttemptedDestinationsApiV1AppAppIdMsgMsgIdEndpointGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `list_attempted_messages_api_v1_app_app_id_endpoint_endpoint_id_msg_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAttemptedMessagesApiV1AppAppIdEndpointEndpointIdMsgGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `list_attempts_api_v1_app_app_id_msg_msg_id_attempt_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAttemptsApiV1AppAppIdMsgMsgIdAttemptGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `list_attempts_by_endpoint_api_v1_app_app_id_attempt_endpoint_endpoint_id_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAttemptsByEndpointApiV1AppAppIdAttemptEndpointEndpointIdGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `list_attempts_by_msg_api_v1_app_app_id_attempt_msg_msg_id_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAttemptsByMsgApiV1AppAppIdAttemptMsgMsgIdGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `list_attempts_for_endpoint_api_v1_app_app_id_msg_msg_id_endpoint_endpoint_id_attempt_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAttemptsForEndpointApiV1AppAppIdMsgMsgIdEndpointEndpointIdAttemptGetError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `resend_webhook_api_v1_app_app_id_msg_msg_id_endpoint_endpoint_id_resend_post`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResendWebhookApiV1AppAppIdMsgMsgIdEndpointEndpointIdResendPostError {
    Status401(crate::models::HttpErrorOut),
    Status403(crate::models::HttpErrorOut),
    Status404(crate::models::HttpErrorOut),
    Status409(crate::models::HttpErrorOut),
    Status422(crate::models::HttpValidationError),
    Status429(crate::models::HttpErrorOut),
    UnknownValue(serde_json::Value),
}


/// `msg_id`: Use a message id or a message `eventId`
pub async fn get_attempt_api_v1_app_app_id_msg_msg_id_attempt_attempt_id_get(configuration: &configuration::Configuration, params: GetAttemptApiV1AppAppIdMsgMsgIdAttemptAttemptIdGetParams) -> Result<crate::models::MessageAttemptOut, Error<GetAttemptApiV1AppAppIdMsgMsgIdAttemptAttemptIdGetError>> {
    // unbox the parameters
    let attempt_id = params.attempt_id;
    let msg_id = params.msg_id;
    let app_id = params.app_id;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/msg/{msg_id}/attempt/{attempt_id}/", configuration.base_path, attempt_id=crate::apis::urlencode(attempt_id), msg_id=crate::apis::urlencode(msg_id), app_id=crate::apis::urlencode(app_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<GetAttemptApiV1AppAppIdMsgMsgIdAttemptAttemptIdGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Calculate and return headers used on a given message attempt
pub async fn get_attempt_headers_api_v1_app_app_id_msg_msg_id_attempt_attempt_id_headers_get(configuration: &configuration::Configuration, params: GetAttemptHeadersApiV1AppAppIdMsgMsgIdAttemptAttemptIdHeadersGetParams) -> Result<crate::models::MessageAttemptHeadersOut, Error<GetAttemptHeadersApiV1AppAppIdMsgMsgIdAttemptAttemptIdHeadersGetError>> {
    // unbox the parameters
    let app_id = params.app_id;
    let msg_id = params.msg_id;
    let attempt_id = params.attempt_id;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/msg/{msg_id}/attempt/{attempt_id}/headers/", configuration.base_path, app_id=crate::apis::urlencode(app_id), msg_id=crate::apis::urlencode(msg_id), attempt_id=crate::apis::urlencode(attempt_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<GetAttemptHeadersApiV1AppAppIdMsgMsgIdAttemptAttemptIdHeadersGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// `msg_id`: Use a message id or a message `eventId`
pub async fn list_attempted_destinations_api_v1_app_app_id_msg_msg_id_endpoint_get(configuration: &configuration::Configuration, params: ListAttemptedDestinationsApiV1AppAppIdMsgMsgIdEndpointGetParams) -> Result<crate::models::ListResponseMessageEndpointOut, Error<ListAttemptedDestinationsApiV1AppAppIdMsgMsgIdEndpointGetError>> {
    // unbox the parameters
    let msg_id = params.msg_id;
    let app_id = params.app_id;
    let iterator = params.iterator;
    let limit = params.limit;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/msg/{msg_id}/endpoint/", configuration.base_path, msg_id=crate::apis::urlencode(msg_id), app_id=crate::apis::urlencode(app_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = iterator {
        local_var_req_builder = local_var_req_builder.query(&[("iterator", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = limit {
        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<ListAttemptedDestinationsApiV1AppAppIdMsgMsgIdEndpointGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// List messages for a particular endpoint. Additionally includes metadata about the latest message attempt.  The `before` parameter lets you filter all items created before a certain date and is ignored if an iterator is passed.
pub async fn list_attempted_messages_api_v1_app_app_id_endpoint_endpoint_id_msg_get(configuration: &configuration::Configuration, params: ListAttemptedMessagesApiV1AppAppIdEndpointEndpointIdMsgGetParams) -> Result<crate::models::ListResponseEndpointMessageOut, Error<ListAttemptedMessagesApiV1AppAppIdEndpointEndpointIdMsgGetError>> {
    // unbox the parameters
    let endpoint_id = params.endpoint_id;
    let app_id = params.app_id;
    let iterator = params.iterator;
    let limit = params.limit;
    let channel = params.channel;
    let status = params.status;
    let before = params.before;
    let after = params.after;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/endpoint/{endpoint_id}/msg/", configuration.base_path, endpoint_id=crate::apis::urlencode(endpoint_id), app_id=crate::apis::urlencode(app_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = iterator {
        local_var_req_builder = local_var_req_builder.query(&[("iterator", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = limit {
        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = channel {
        local_var_req_builder = local_var_req_builder.query(&[("channel", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = status {
        local_var_req_builder = local_var_req_builder.query(&[("status", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = before {
        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = after {
        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<ListAttemptedMessagesApiV1AppAppIdEndpointEndpointIdMsgGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Deprecated: Please use \"List Attempts by Endpoint\" and \"List Attempts by Msg\" instead.  `msg_id`: Use a message id or a message `eventId`
pub async fn list_attempts_api_v1_app_app_id_msg_msg_id_attempt_get(configuration: &configuration::Configuration, params: ListAttemptsApiV1AppAppIdMsgMsgIdAttemptGetParams) -> Result<crate::models::ListResponseMessageAttemptOut, Error<ListAttemptsApiV1AppAppIdMsgMsgIdAttemptGetError>> {
    // unbox the parameters
    let app_id = params.app_id;
    let msg_id = params.msg_id;
    let iterator = params.iterator;
    let limit = params.limit;
    let endpoint_id = params.endpoint_id;
    let event_types = params.event_types;
    let channel = params.channel;
    let status = params.status;
    let before = params.before;
    let after = params.after;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/msg/{msg_id}/attempt/", configuration.base_path, app_id=crate::apis::urlencode(app_id), msg_id=crate::apis::urlencode(msg_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = iterator {
        local_var_req_builder = local_var_req_builder.query(&[("iterator", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = limit {
        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = endpoint_id {
        local_var_req_builder = local_var_req_builder.query(&[("endpoint_id", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = event_types {
        local_var_req_builder = local_var_req_builder.query(&[("event_types", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
    }
    if let Some(ref local_var_str) = channel {
        local_var_req_builder = local_var_req_builder.query(&[("channel", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = status {
        local_var_req_builder = local_var_req_builder.query(&[("status", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = before {
        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = after {
        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<ListAttemptsApiV1AppAppIdMsgMsgIdAttemptGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// List attempts by endpoint id
pub async fn list_attempts_by_endpoint_api_v1_app_app_id_attempt_endpoint_endpoint_id_get(configuration: &configuration::Configuration, params: ListAttemptsByEndpointApiV1AppAppIdAttemptEndpointEndpointIdGetParams) -> Result<crate::models::ListResponseMessageAttemptOut, Error<ListAttemptsByEndpointApiV1AppAppIdAttemptEndpointEndpointIdGetError>> {
    // unbox the parameters
    let app_id = params.app_id;
    let endpoint_id = params.endpoint_id;
    let iterator = params.iterator;
    let limit = params.limit;
    let status = params.status;
    let status_code_class = params.status_code_class;
    let event_types = params.event_types;
    let channel = params.channel;
    let before = params.before;
    let after = params.after;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/attempt/endpoint/{endpoint_id}/", configuration.base_path, app_id=crate::apis::urlencode(app_id), endpoint_id=crate::apis::urlencode(endpoint_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = iterator {
        local_var_req_builder = local_var_req_builder.query(&[("iterator", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = limit {
        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = status {
        local_var_req_builder = local_var_req_builder.query(&[("status", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = status_code_class {
        local_var_req_builder = local_var_req_builder.query(&[("status_code_class", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = event_types {
        local_var_req_builder = local_var_req_builder.query(&[("event_types", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
    }
    if let Some(ref local_var_str) = channel {
        local_var_req_builder = local_var_req_builder.query(&[("channel", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = before {
        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = after {
        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<ListAttemptsByEndpointApiV1AppAppIdAttemptEndpointEndpointIdGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// List attempts by message id
pub async fn list_attempts_by_msg_api_v1_app_app_id_attempt_msg_msg_id_get(configuration: &configuration::Configuration, params: ListAttemptsByMsgApiV1AppAppIdAttemptMsgMsgIdGetParams) -> Result<crate::models::ListResponseMessageAttemptOut, Error<ListAttemptsByMsgApiV1AppAppIdAttemptMsgMsgIdGetError>> {
    // unbox the parameters
    let app_id = params.app_id;
    let msg_id = params.msg_id;
    let endpoint_id = params.endpoint_id;
    let iterator = params.iterator;
    let limit = params.limit;
    let status = params.status;
    let status_code_class = params.status_code_class;
    let event_types = params.event_types;
    let channel = params.channel;
    let before = params.before;
    let after = params.after;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/attempt/msg/{msg_id}/", configuration.base_path, app_id=crate::apis::urlencode(app_id), msg_id=crate::apis::urlencode(msg_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = endpoint_id {
        local_var_req_builder = local_var_req_builder.query(&[("endpoint_id", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = iterator {
        local_var_req_builder = local_var_req_builder.query(&[("iterator", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = limit {
        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = status {
        local_var_req_builder = local_var_req_builder.query(&[("status", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = status_code_class {
        local_var_req_builder = local_var_req_builder.query(&[("status_code_class", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = event_types {
        local_var_req_builder = local_var_req_builder.query(&[("event_types", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
    }
    if let Some(ref local_var_str) = channel {
        local_var_req_builder = local_var_req_builder.query(&[("channel", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = before {
        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = after {
        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<ListAttemptsByMsgApiV1AppAppIdAttemptMsgMsgIdGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// DEPRECATED: please use list_attempts with endpoint_id as a query parameter instead.  List the message attempts for a particular endpoint.  Returning the endpoint.  The `before` parameter lets you filter all items created before a certain date and is ignored if an iterator is passed.
pub async fn list_attempts_for_endpoint_api_v1_app_app_id_msg_msg_id_endpoint_endpoint_id_attempt_get(configuration: &configuration::Configuration, params: ListAttemptsForEndpointApiV1AppAppIdMsgMsgIdEndpointEndpointIdAttemptGetParams) -> Result<crate::models::ListResponseMessageAttemptEndpointOut, Error<ListAttemptsForEndpointApiV1AppAppIdMsgMsgIdEndpointEndpointIdAttemptGetError>> {
    // unbox the parameters
    let msg_id = params.msg_id;
    let app_id = params.app_id;
    let endpoint_id = params.endpoint_id;
    let iterator = params.iterator;
    let limit = params.limit;
    let event_types = params.event_types;
    let channel = params.channel;
    let status = params.status;
    let before = params.before;
    let after = params.after;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/msg/{msg_id}/endpoint/{endpoint_id}/attempt/", configuration.base_path, msg_id=crate::apis::urlencode(msg_id), app_id=crate::apis::urlencode(app_id), endpoint_id=crate::apis::urlencode(endpoint_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = iterator {
        local_var_req_builder = local_var_req_builder.query(&[("iterator", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = limit {
        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = event_types {
        local_var_req_builder = local_var_req_builder.query(&[("event_types", &local_var_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
    }
    if let Some(ref local_var_str) = channel {
        local_var_req_builder = local_var_req_builder.query(&[("channel", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = status {
        local_var_req_builder = local_var_req_builder.query(&[("status", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = before {
        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = after {
        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<ListAttemptsForEndpointApiV1AppAppIdMsgMsgIdEndpointEndpointIdAttemptGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Resend a message to the specified endpoint.
pub async fn resend_webhook_api_v1_app_app_id_msg_msg_id_endpoint_endpoint_id_resend_post(configuration: &configuration::Configuration, params: ResendWebhookApiV1AppAppIdMsgMsgIdEndpointEndpointIdResendPostParams) -> Result<(), Error<ResendWebhookApiV1AppAppIdMsgMsgIdEndpointEndpointIdResendPostError>> {
    // unbox the parameters
    let endpoint_id = params.endpoint_id;
    let msg_id = params.msg_id;
    let app_id = params.app_id;
    let idempotency_key = params.idempotency_key;


    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/api/v1/app/{app_id}/msg/{msg_id}/endpoint/{endpoint_id}/resend/", configuration.base_path, endpoint_id=crate::apis::urlencode(endpoint_id), msg_id=crate::apis::urlencode(msg_id), app_id=crate::apis::urlencode(app_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(local_var_param_value) = idempotency_key {
        local_var_req_builder = local_var_req_builder.header("idempotency-key", local_var_param_value.to_string());
    }
    if let Some(ref local_var_token) = configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        Ok(())
    } else {
        let local_var_entity: Option<ResendWebhookApiV1AppAppIdMsgMsgIdEndpointEndpointIdResendPostError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

