/*
 * Tapis Pods Service
 *
 *  The Pods Service is a web service and distributed computing platform providing pods-as-a-service (PaaS). The service  implements a message broker and processor model that requests pods, alongside a health module to poll for pod data, including logs, status, and health. The primary use of this service is to have quick to deploy long-lived services based on Docker images that are exposed via HTTP or TCP endpoints listed by the API.  **The Pods service provides functionality for two types of pod solutions:**  * **Templated Pods** for run-as-is popular images. Neo4J is one example, the template manages TCP ports, user creation, and permissions.  * **Custom Pods** for arbitrary docker images with less functionality. In this case we will expose port 5000 and do nothing else.   The live-docs act as the most up-to-date API reference. Visit the [documentation for more information](https://tapis.readthedocs.io/en/latest/technical/pods.html).
 *
 * The version of the OpenAPI document: 26Q1.1
 * Contact: cicsupport@tacc.utexas.edu
 * Generated by: https://openapi-generator.tech
 */

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

/// struct for typed errors of method [`delete_pod_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeletePodPermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_snapshot_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSnapshotPermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_template_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteTemplatePermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_volume_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteVolumePermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_pod_permissions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPodPermissionsError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_snapshot_permissions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSnapshotPermissionsError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_template_permissions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTemplatePermissionsError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_volume_permissions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetVolumePermissionsError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`set_pod_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetPodPermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`set_snapshot_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetSnapshotPermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`set_template_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetTemplatePermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`set_volume_permission`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetVolumePermissionError {
    Status422(models::HttpValidationError),
    UnknownValue(serde_json::Value),
}

/// Delete a permission from a pod.  Returns updated pod permissions.
pub async fn delete_pod_permission(
    configuration: &configuration::Configuration,
    pod_id: &str,
    user: &str,
) -> Result<models::PodPermissionsResponse, Error<DeletePodPermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_pod_id = pod_id;
    let p_path_user = user;

    let uri_str = format!(
        "{}/pods/{pod_id}/permissions/{user}",
        configuration.base_path,
        pod_id = p_path_pod_id,
        user = p_path_user
    );
    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());
    }

    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::PodPermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::PodPermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeletePodPermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete a permission from a snapshot.  Returns updated snapshot permissions.
pub async fn delete_snapshot_permission(
    configuration: &configuration::Configuration,
    snapshot_id: &str,
    user: &str,
) -> Result<models::SnapshotPermissionsResponse, Error<DeleteSnapshotPermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_snapshot_id = snapshot_id;
    let p_path_user = user;

    let uri_str = format!(
        "{}/pods/snapshots/{snapshot_id}/permissions/{user}",
        configuration.base_path,
        snapshot_id = p_path_snapshot_id,
        user = p_path_user
    );
    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());
    }

    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::SnapshotPermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::SnapshotPermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteSnapshotPermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete a permission from a template.  Returns updated template permissions.
pub async fn delete_template_permission(
    configuration: &configuration::Configuration,
    template_id: &str,
    user: &str,
) -> Result<models::TemplatePermissionsResponse, Error<DeleteTemplatePermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_template_id = template_id;
    let p_path_user = user;

    let uri_str = format!(
        "{}/pods/templates/{template_id}/permissions/{user}",
        configuration.base_path,
        template_id = p_path_template_id,
        user = p_path_user
    );
    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());
    }

    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::TemplatePermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::TemplatePermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteTemplatePermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete a permission from a volume.  Returns updated volume permissions.
pub async fn delete_volume_permission(
    configuration: &configuration::Configuration,
    volume_id: &str,
    user: &str,
) -> Result<models::VolumePermissionsResponse, Error<DeleteVolumePermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_volume_id = volume_id;
    let p_path_user = user;

    let uri_str = format!(
        "{}/pods/volumes/{volume_id}/permissions/{user}",
        configuration.base_path,
        volume_id = p_path_volume_id,
        user = p_path_user
    );
    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());
    }

    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::VolumePermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::VolumePermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteVolumePermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Get a pods permissions.  Note: - There are 3 levels of permissions, READ, USER, and ADMIN. - Permissions are granted/revoked to individual TACC usernames.  Returns all pod permissions.
pub async fn get_pod_permissions(
    configuration: &configuration::Configuration,
    pod_id: &str,
) -> Result<models::PodPermissionsResponse, Error<GetPodPermissionsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_pod_id = pod_id;

    let uri_str = format!(
        "{}/pods/{pod_id}/permissions",
        configuration.base_path,
        pod_id = p_path_pod_id
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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::PodPermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::PodPermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetPodPermissionsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Get a snapshots permissions.  Note: - There are 3 levels of permissions, READ, USER, and ADMIN. - Permissions are granted/revoked to individual TACC usernames.  Returns all volue permissions.
pub async fn get_snapshot_permissions(
    configuration: &configuration::Configuration,
    snapshot_id: &str,
) -> Result<models::SnapshotPermissionsResponse, Error<GetSnapshotPermissionsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_snapshot_id = snapshot_id;

    let uri_str = format!(
        "{}/pods/snapshots/{snapshot_id}/permissions",
        configuration.base_path,
        snapshot_id = p_path_snapshot_id
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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::SnapshotPermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::SnapshotPermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetSnapshotPermissionsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Get a templates permissions.  Note: - There are 3 levels of permissions, READ, USER, and ADMIN. - Permissions are granted/revoked to individual TACC usernames. - Permissions can be set for TENANT or SITE keys for tenant-level or site-level sharing.  Returns all template permissions.
pub async fn get_template_permissions(
    configuration: &configuration::Configuration,
    template_id: &str,
) -> Result<models::TemplatePermissionsResponse, Error<GetTemplatePermissionsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_template_id = template_id;

    let uri_str = format!(
        "{}/pods/templates/{template_id}/permissions",
        configuration.base_path,
        template_id = p_path_template_id
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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::TemplatePermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::TemplatePermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetTemplatePermissionsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Get a volumes permissions.  Note: - There are 3 levels of permissions, READ, USER, and ADMIN. - Permissions are granted/revoked to individual TACC usernames.  Returns all volue permissions.
pub async fn get_volume_permissions(
    configuration: &configuration::Configuration,
    volume_id: &str,
) -> Result<models::VolumePermissionsResponse, Error<GetVolumePermissionsError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_volume_id = volume_id;

    let uri_str = format!(
        "{}/pods/volumes/{volume_id}/permissions",
        configuration.base_path,
        volume_id = p_path_volume_id
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    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::VolumePermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::VolumePermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetVolumePermissionsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Set a permission for a pod.  Permission formats: - username:LEVEL - Standard user permission (e.g., 'jsmith:READ') - tenant.<tenant_id>:READ - Cross-tenant auth permission. Allows users from <tenant_id> to authenticate   to this pod via tapis_auth. Only settable by admins. Must use READ level. ex. tenant.public, tenant.dev  Notes: - 'tenant.*' permissions require admin privileges (like '**' on templates) - 'tenant.*' permissions only support READ level (they gate cross-tenant auth access, not authorization) - There are 3 levels of permissions, READ, USER, and ADMIN.  Returns updated pod permissions.
pub async fn set_pod_permission(
    configuration: &configuration::Configuration,
    pod_id: &str,
    set_permission: models::SetPermission,
) -> Result<models::PodPermissionsResponse, Error<SetPodPermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_pod_id = pod_id;
    let p_body_set_permission = set_permission;

    let uri_str = format!(
        "{}/pods/{pod_id}/permissions",
        configuration.base_path,
        pod_id = p_path_pod_id
    );
    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());
    }
    req_builder = req_builder.json(&p_body_set_permission);

    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::PodPermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::PodPermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SetPodPermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Set a permission for a snapshot.  Returns updated snapshot permissions.
pub async fn set_snapshot_permission(
    configuration: &configuration::Configuration,
    snapshot_id: &str,
    set_permission: models::SetPermission,
) -> Result<models::SnapshotPermissionsResponse, Error<SetSnapshotPermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_snapshot_id = snapshot_id;
    let p_body_set_permission = set_permission;

    let uri_str = format!(
        "{}/pods/snapshots/{snapshot_id}/permissions",
        configuration.base_path,
        snapshot_id = p_path_snapshot_id
    );
    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());
    }
    req_builder = req_builder.json(&p_body_set_permission);

    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::SnapshotPermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::SnapshotPermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SetSnapshotPermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Set a permission for a template.  Permission formats: - username:LEVEL - Standard user permission (e.g., 'jsmith:READ') - **:READ - Site-wide public access (all users across all tenants can READ) [ADMIN ONLY] - tenant.<tenant_id>:READ - Tenant-wide public access (all users in specified tenant can READ) [ADMIN ONLY]  Notes: - Both '**' and 'tenant.*' only allow READ level for security - '**' and 'tenant.*' permissions require admin privileges - There are 3 levels of permissions, READ, USER, and ADMIN. - Permissions are granted to an individual usernames and are active across tenants.  Returns updated template permissions.
pub async fn set_template_permission(
    configuration: &configuration::Configuration,
    template_id: &str,
    set_permission: models::SetPermission,
) -> Result<models::TemplatePermissionsResponse, Error<SetTemplatePermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_template_id = template_id;
    let p_body_set_permission = set_permission;

    let uri_str = format!(
        "{}/pods/templates/{template_id}/permissions",
        configuration.base_path,
        template_id = p_path_template_id
    );
    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());
    }
    req_builder = req_builder.json(&p_body_set_permission);

    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::TemplatePermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::TemplatePermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SetTemplatePermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Set a permission for a volume.  Returns updated volume permissions.
pub async fn set_volume_permission(
    configuration: &configuration::Configuration,
    volume_id: &str,
    set_permission: models::SetPermission,
) -> Result<models::VolumePermissionsResponse, Error<SetVolumePermissionError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_volume_id = volume_id;
    let p_body_set_permission = set_permission;

    let uri_str = format!(
        "{}/pods/volumes/{volume_id}/permissions",
        configuration.base_path,
        volume_id = p_path_volume_id
    );
    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());
    }
    req_builder = req_builder.json(&p_body_set_permission);

    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::VolumePermissionsResponse`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::VolumePermissionsResponse`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SetVolumePermissionError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}
