/*
 * Tapis Notifications API
 *
 * The Tapis Notifications API provides for management of subscriptions and event publication
 *
 * The version of the OpenAPI document: 25Q4.0
 * Contact: cicsupport@tacc.utexas.edu
 * Generated by: https://openapi-generator.tech
 */

use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};

/// struct for typed errors of method [`delete_subscription_by_name`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSubscriptionByNameError {
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_subscription_by_uuid`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSubscriptionByUuidError {
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_subscriptions_by_subject`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSubscriptionsBySubjectError {
    Status401(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`disable_subscription`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DisableSubscriptionError {
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`enable_subscription`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EnableSubscriptionError {
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_subscription_by_name`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSubscriptionByNameError {
    Status400(models::RespBasic),
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_subscription_by_uuid`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSubscriptionByUuidError {
    Status400(models::RespBasic),
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_subscriptions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSubscriptionsError {
    Status400(models::RespBasic),
    Status401(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`is_enabled`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum IsEnabledError {
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`patch_subscription_by_name`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PatchSubscriptionByNameError {
    Status400(models::RespBasic),
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`post_subscription`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostSubscriptionError {
    Status400(models::RespBasic),
    Status401(models::RespBasic),
    Status409(models::RespResourceUrl),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`search_subscriptions_query_parameters`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchSubscriptionsQueryParametersError {
    Status400(models::RespBasic),
    Status401(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`search_subscriptions_request_body`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchSubscriptionsRequestBodyError {
    Status400(models::RespBasic),
    Status401(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`update_ttl`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateTtlError {
    Status401(models::RespBasic),
    Status404(models::RespBasic),
    Status500(models::RespBasic),
    UnknownValue(serde_json::Value),
}

/// Delete a subscription. Only services may perform this operation.  Events will stop being delivered. Subscription must be re-created to resume event delivery. Query parameter *ownedBy* may be used to delete a subscription owned by another user. Only services or tenant administrators may set *ownedBy*.
pub async fn delete_subscription_by_name(
    configuration: &configuration::Configuration,
    name: &str,
    owned_by: Option<&str>,
) -> Result<models::RespChangeCount, Error<DeleteSubscriptionByNameError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_name = name;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/byName/{name}",
        configuration.base_path,
        name = crate::apis::urlencode(p_path_name)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespChangeCount`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespChangeCount`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteSubscriptionByNameError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete a subscription whose UUID matches the provided value. Only services may perform this operation.
pub async fn delete_subscription_by_uuid(
    configuration: &configuration::Configuration,
    uuid: &str,
) -> Result<models::RespChangeCount, Error<DeleteSubscriptionByUuidError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_uuid = uuid;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/byUuid/{uuid}",
        configuration.base_path,
        uuid = crate::apis::urlencode(p_path_uuid)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespChangeCount`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespChangeCount`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteSubscriptionByUuidError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete all subscriptions whose *subjectFilter* exactly matches the specific *subject* provided. Only services may perform this operation.  Query parameter *ownedBy* may be used to delete subscriptions owned by a user other than the requesting user. Ignored if *anyOwner* is set to true. Only services or tenant administrators may set *ownedBy*.  Query parameter *anyOwner* may be used to delete subscriptions owned by any user. Query parameter *anyOwner* takes precedence over parameter *ownedBy*. Only services may set *anyOwner*.
pub async fn delete_subscriptions_by_subject(
    configuration: &configuration::Configuration,
    subject: &str,
    owned_by: Option<&str>,
    any_owner: Option<bool>,
) -> Result<models::RespChangeCount, Error<DeleteSubscriptionsBySubjectError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_subject = subject;
    let p_query_owned_by = owned_by;
    let p_query_any_owner = any_owner;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/bySubject/{subject}",
        configuration.base_path,
        subject = crate::apis::urlencode(p_path_subject)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_any_owner {
        req_builder = req_builder.query(&[("anyOwner", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespChangeCount`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespChangeCount`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteSubscriptionsBySubjectError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Update a subscription to be inactive. Only services may perform this operation.  Matching events will stop being delivered. Query parameter *ownedBy* may be used to disable a subscription owned by another user. Only services or tenant administrators may set *ownedBy*.
pub async fn disable_subscription(
    configuration: &configuration::Configuration,
    name: &str,
    owned_by: Option<&str>,
) -> Result<models::RespChangeCount, Error<DisableSubscriptionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_name = name;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/{name}/disable",
        configuration.base_path,
        name = crate::apis::urlencode(p_path_name)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespChangeCount`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespChangeCount`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DisableSubscriptionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Update a subscription to be active. Only services may perform this operation.  Matching events will start being delivered. Query parameter *ownedBy* may be used to enable a subscription owned by another user. Only services or tenant administrators may set *ownedBy*.
pub async fn enable_subscription(
    configuration: &configuration::Configuration,
    name: &str,
    owned_by: Option<&str>,
) -> Result<models::RespChangeCount, Error<EnableSubscriptionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_name = name;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/{name}/enable",
        configuration.base_path,
        name = crate::apis::urlencode(p_path_name)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespChangeCount`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespChangeCount`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<EnableSubscriptionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Retrieve a subscription owned by the requesting user and whose name matches the provided value. Query parameter *ownedBy* may be used to retrieve a subscription owned by another user. Only services or tenant administrators may set the *ownedBy* query parameter.  Summary of subscription attributes. For details please see *postSubscription*:   - owner: Tapis user who owns the subscription.   - name: Short descriptive name.   - description: Optional more verbose description.   - enabled: Indicates if subscription is currently active.    - typeFilter: Filter to use when matching events. Format is *service.category.detail*. Each field may be a specific type or the wildcard character *.   - subjectFilter: Filter to use when matching events. Filter for subject. May be wildcard character *.   - deliveryTargets: List of delivery targets to be used when delivering a matching event.   - ttlMinutes: Time to live in minutes. 0 indicates no expiration.   - uuid: A UUID generated by the service.   - expiry: Time at which the subscription expires and will be deleted. Maintained by the service.   - created: When created. Maintained by the service.   - updated: When last updated. Maintained by the service.
pub async fn get_subscription_by_name(
    configuration: &configuration::Configuration,
    name: &str,
    select: Option<&str>,
    owned_by: Option<&str>,
) -> Result<models::RespSubscription, Error<GetSubscriptionByNameError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_name = name;
    let p_query_select = select;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/byName/{name}",
        configuration.base_path,
        name = crate::apis::urlencode(p_path_name)
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_select {
        req_builder = req_builder.query(&[("select", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSubscription`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSubscription`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetSubscriptionByNameError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Retrieve a subscription whose UUID matches the provided value.  Summary of subscription attributes. For details please see *postSubscription*:   - owner: Tapis user who owns the subscription.   - name: Short descriptive name.   - description: Optional more verbose description.   - enabled: Indicates if subscription is currently active.    - typeFilter: Filter to use when matching events. Format is *service.category.detail*. Each field may be a specific type or the wildcard character *.   - subjectFilter: Filter to use when matching events. Filter for subject. May be wildcard character *.   - deliveryTargets: List of delivery targets to be used when delivering a matching event.   - ttlMinutes: Time to live in minutes. 0 indicates no expiration.   - uuid: A UUID generated by the service.   - expiry: Time at which the subscription expires and will be deleted. Maintained by the service.   - created: When created. Maintained by the service.   - updated: When last updated. Maintained by the service.
pub async fn get_subscription_by_uuid(
    configuration: &configuration::Configuration,
    uuid: &str,
    select: Option<&str>,
) -> Result<models::RespSubscription, Error<GetSubscriptionByUuidError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_uuid = uuid;
    let p_query_select = select;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/byUuid/{uuid}",
        configuration.base_path,
        uuid = crate::apis::urlencode(p_path_uuid)
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_select {
        req_builder = req_builder.query(&[("select", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSubscription`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSubscription`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetSubscriptionByUuidError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Retrieve list of subscriptions owned by the requesting user. Use search and select query parameters to limit results.  Query parameter *ownedBy* may be used to retrieve subscriptions owned by a user other than the requesting user. Ignored if *anyOwner* is set to true. Only services or tenant administrators may set *ownedBy*.  Query parameter *anyOwner* may be used to retrieve all subscriptions owned by any user. Query parameter *anyOwner* takes precedence over parameter *ownedBy*. Only services may set *anyOwner*.  
pub async fn get_subscriptions(
    configuration: &configuration::Configuration,
    search: Option<&str>,
    limit: Option<i32>,
    order_by: Option<&str>,
    skip: Option<i32>,
    start_after: Option<&str>,
    compute_total: Option<bool>,
    select: Option<&str>,
    owned_by: Option<&str>,
    any_owner: Option<bool>,
) -> Result<models::RespSubscriptions, Error<GetSubscriptionsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_search = search;
    let p_query_limit = limit;
    let p_query_order_by = order_by;
    let p_query_skip = skip;
    let p_query_start_after = start_after;
    let p_query_compute_total = compute_total;
    let p_query_select = select;
    let p_query_owned_by = owned_by;
    let p_query_any_owner = any_owner;

    let uri_str = format!("{}/v3/notifications/subscriptions", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_search {
        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_order_by {
        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_skip {
        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_start_after {
        req_builder = req_builder.query(&[("startAfter", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_compute_total {
        req_builder = req_builder.query(&[("computeTotal", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_select {
        req_builder = req_builder.query(&[("select", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_any_owner {
        req_builder = req_builder.query(&[("anyOwner", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSubscriptions`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSubscriptions`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetSubscriptionsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Check if a subscription owned by the requesting user is currently active. Query parameter *ownedBy* may be used to check a subscription owned by another user. Only services or tenant administrators may set *ownedBy*.
pub async fn is_enabled(
    configuration: &configuration::Configuration,
    name: &str,
    owned_by: Option<&str>,
) -> Result<models::RespBoolean, Error<IsEnabledError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_name = name;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/{name}/isEnabled",
        configuration.base_path,
        name = crate::apis::urlencode(p_path_name)
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBoolean`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBoolean`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<IsEnabledError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Update selected attributes of a subscription. Only services may perform this operation.  Request body may only contain updatable attributes. Subscription must exist. Query parameter *ownedBy* may be used to patch a subscription owned by another user. Only services or tenant administrators may set *ownedBy*.  Attributes that may not be updated via PATCH are    - name   - owner   - enabled   - ttlMinutes  Note that the attributes *enabled* and *ttlMinutes* may be modified using other endpoints.
pub async fn patch_subscription_by_name(
    configuration: &configuration::Configuration,
    name: &str,
    req_patch_subscription: models::ReqPatchSubscription,
    owned_by: Option<&str>,
) -> Result<models::RespResourceUrl, Error<PatchSubscriptionByNameError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_name = name;
    let p_body_req_patch_subscription = req_patch_subscription;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/byName/{name}",
        configuration.base_path,
        name = crate::apis::urlencode(p_path_name)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::PATCH, &uri_str);

    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };
    req_builder = req_builder.json(&p_body_req_patch_subscription);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespResourceUrl`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PatchSubscriptionByNameError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Create a subscription using a request body. Only services may perform this operation.  For each owner the *name* must be unique and can be composed of alphanumeric characters and the following special characters [-._~]. If attribute *name* is not provided then the service will generate one. The attributes *typeFilter*, *subjectFilter* and *deliveryTargets* are required.  Subscription attributes:   - name: Optional short descriptive name. *owner+name* must be unique. If one is not provided the service will create one.   - description: Optional more verbose description. Maximum length of 2048 characters.   - owner: A specific user set at create time. Default is *${apiUserId}*.   - enabled: Indicates if subscription is active. By default enabled is true.   - typeFilter: Filter to use when matching events. Filter for event type. Has three dot separated parts: *service*, *category* and *detail*. Each field may be a specific type or the wildcard character. Examples are *jobs.job.complete*, *jobs.new_status.\\**.   - subjectFilter: Filter to use when matching events. Filter for subject. This may be a specific subject such as a job Id or the wildcard character *.   - deliveryTargets: List of delivery targets to be used when delivering a matching event. Must have at least one. Each target includes delivery method (EMAIL or WEBHOOK) and delivery address.   - ttlMinutes: Time to live in minutes specified when subscription is created or TTL is updated. Service will compute expiry based on TTL. Default is one week from creation. Value of 0 indicates no expiration.
pub async fn post_subscription(
    configuration: &configuration::Configuration,
    req_post_subscription: models::ReqPostSubscription,
) -> Result<models::RespResourceUrl, Error<PostSubscriptionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_req_post_subscription = req_post_subscription;

    let uri_str = format!("{}/v3/notifications/subscriptions", configuration.base_path);
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };
    req_builder = req_builder.json(&p_body_req_post_subscription);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespResourceUrl`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PostSubscriptionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Retrieve details for subscriptions owned by the requesting user. Use query parameters to specify search conditions. For example name.eq=MySubscription. Query parameter *ownedBy* may be used to retrieve subscriptions owned by another user. Only services or tenant administrators may set *ownedBy*.
pub async fn search_subscriptions_query_parameters(
    configuration: &configuration::Configuration,
    free_form_parameter_name: Option<std::collections::HashMap<String, String>>,
    limit: Option<i32>,
    order_by: Option<&str>,
    skip: Option<i32>,
    start_after: Option<&str>,
    compute_total: Option<bool>,
    select: Option<&str>,
    owned_by: Option<&str>,
) -> Result<models::RespSubscriptions, Error<SearchSubscriptionsQueryParametersError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_free_form_parameter_name = free_form_parameter_name;
    let p_query_limit = limit;
    let p_query_order_by = order_by;
    let p_query_skip = skip;
    let p_query_start_after = start_after;
    let p_query_compute_total = compute_total;
    let p_query_select = select;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/search",
        configuration.base_path
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_free_form_parameter_name {
        req_builder = req_builder.query(&[(
            "freeFormParameterName",
            &serde_json::to_string(param_value)?,
        )]);
    }
    if let Some(ref param_value) = p_query_limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_order_by {
        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_skip {
        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_start_after {
        req_builder = req_builder.query(&[("startAfter", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_compute_total {
        req_builder = req_builder.query(&[("computeTotal", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_select {
        req_builder = req_builder.query(&[("select", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSubscriptions`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSubscriptions`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SearchSubscriptionsQueryParametersError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Retrieve details for subscriptions owned by the requesting user. Use request body to specify SQL-like search conditions. Query parameter *ownedBy* may be used to retrieve subscriptions owned by another user. Only services or tenant administrators may set *ownedBy*.
pub async fn search_subscriptions_request_body(
    configuration: &configuration::Configuration,
    req_search_subscriptions: models::ReqSearchSubscriptions,
    limit: Option<i32>,
    order_by: Option<&str>,
    skip: Option<i32>,
    start_after: Option<&str>,
    compute_total: Option<bool>,
    select: Option<&str>,
    owned_by: Option<&str>,
) -> Result<models::RespSubscriptions, Error<SearchSubscriptionsRequestBodyError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_req_search_subscriptions = req_search_subscriptions;
    let p_query_limit = limit;
    let p_query_order_by = order_by;
    let p_query_skip = skip;
    let p_query_start_after = start_after;
    let p_query_compute_total = compute_total;
    let p_query_select = select;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/search",
        configuration.base_path
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref param_value) = p_query_limit {
        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_order_by {
        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_skip {
        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_start_after {
        req_builder = req_builder.query(&[("startAfter", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_compute_total {
        req_builder = req_builder.query(&[("computeTotal", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_select {
        req_builder = req_builder.query(&[("select", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };
    req_builder = req_builder.json(&p_body_req_search_subscriptions);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSubscriptions`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSubscriptions`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SearchSubscriptionsRequestBodyError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Update Time-To-Live (TTL) for a subscription. Only services may perform this operation.  TTL provided as number of minutes. Use 0 to indicate subscription should never expire. Query parameter *ownedBy* may be used to update a subscription owned by another user. Only services or tenant administrators may set *ownedBy*.
pub async fn update_ttl(
    configuration: &configuration::Configuration,
    name: &str,
    ttl_minutes: i32,
    owned_by: Option<&str>,
) -> Result<models::RespChangeCount, Error<UpdateTtlError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_name = name;
    let p_path_ttl_minutes = ttl_minutes;
    let p_query_owned_by = owned_by;

    let uri_str = format!(
        "{}/v3/notifications/subscriptions/{name}/updateTTL/{ttlMinutes}",
        configuration.base_path,
        name = crate::apis::urlencode(p_path_name),
        ttlMinutes = p_path_ttl_minutes
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref param_value) = p_query_owned_by {
        req_builder = req_builder.query(&[("ownedBy", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref apikey) = configuration.api_key {
        let key = apikey.key.clone();
        let value = match apikey.prefix {
            Some(ref prefix) => format!("{} {}", prefix, key),
            None => key,
        };
        req_builder = req_builder.header("X-Tapis-Token", value);
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespChangeCount`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespChangeCount`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<UpdateTtlError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}
