use serde::{Deserialize, Serialize}; /*
                                      * Cloud Storage JSON API
                                      *
                                      * Stores and retrieves potentially large, immutable data objects.
                                      *
                                      * The version of the OpenAPI document: v1
                                      *
                                      * Generated by: https://openapi-generator.tech
                                      */

use reqwest;

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

/// struct for passing parameters to the method [`storage_buckets_delete`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodDeleteParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// If set, only deletes the bucket if its metageneration matches this value.
    pub if_metageneration_match: Option<String>,
    /// If set, only deletes the bucket if its metageneration does not match this value.
    pub if_metageneration_not_match: Option<String>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
}

/// struct for passing parameters to the method [`storage_buckets_get`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodGetParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// Makes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value.
    pub if_metageneration_match: Option<String>,
    /// Makes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value.
    pub if_metageneration_not_match: Option<String>,
    /// Set of properties to return. Defaults to noAcl.
    pub projection: Option<String>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
}

/// struct for passing parameters to the method [`storage_buckets_get_iam_policy`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodGetIamPolicyParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// The IAM policy format version to be returned. If the optionsRequestedPolicyVersion is for an older version that doesn't support part of the requested IAM policy, the request fails.
    pub options_requested_policy_version: Option<i32>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
}

/// struct for passing parameters to the method [`storage_buckets_insert`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodInsertParams {
    /// A valid API project identifier.
    pub project: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// Apply a predefined set of access controls to this bucket.
    pub predefined_acl: Option<String>,
    /// Apply a predefined set of default object access controls to this bucket.
    pub predefined_default_object_acl: Option<String>,
    /// Set of properties to return. Defaults to noAcl, unless the bucket resource specifies acl or defaultObjectAcl properties, when it defaults to full.
    pub projection: Option<String>,
    /// The project to be billed for this request.
    pub user_project: Option<String>,
    pub bucket: Option<crate::google_rest_apis::storage_v1::models::Bucket>,
}

/// struct for passing parameters to the method [`storage_buckets_list`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodListParams {
    /// A valid API project identifier.
    pub project: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// Maximum number of buckets to return in a single response. The service will use this parameter or 1,000 items, whichever is smaller.
    pub max_results: Option<i32>,
    /// A previously-returned page token representing part of the larger set of results to view.
    pub page_token: Option<String>,
    /// Filter results to buckets whose names begin with this prefix.
    pub prefix: Option<String>,
    /// Set of properties to return. Defaults to noAcl.
    pub projection: Option<String>,
    /// The project to be billed for this request.
    pub user_project: Option<String>,
}

/// struct for passing parameters to the method [`storage_buckets_lock_retention_policy`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodLockRetentionPolicyParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Makes the operation conditional on whether bucket's current metageneration matches the given value.
    pub if_metageneration_match: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
}

/// struct for passing parameters to the method [`storage_buckets_patch`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodPatchParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// Makes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value.
    pub if_metageneration_match: Option<String>,
    /// Makes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value.
    pub if_metageneration_not_match: Option<String>,
    /// Apply a predefined set of access controls to this bucket.
    pub predefined_acl: Option<String>,
    /// Apply a predefined set of default object access controls to this bucket.
    pub predefined_default_object_acl: Option<String>,
    /// Set of properties to return. Defaults to full.
    pub projection: Option<String>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
    pub bucket2: Option<crate::google_rest_apis::storage_v1::models::Bucket>,
}

/// struct for passing parameters to the method [`storage_buckets_set_iam_policy`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodSetIamPolicyParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
    pub policy: Option<crate::google_rest_apis::storage_v1::models::Policy>,
}

/// struct for passing parameters to the method [`storage_buckets_test_iam_permissions`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodTestIamPermissionsParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Permissions to test.
    pub permissions: Vec<String>,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
}

/// struct for passing parameters to the method [`storage_buckets_update`]
#[derive(Clone, Debug, Default)]
pub struct StoragePeriodBucketsPeriodUpdateParams {
    /// Name of a bucket.
    pub bucket: String,
    /// Data format for the response.
    pub alt: Option<String>,
    /// Selector specifying which fields to include in a partial response.
    pub fields: Option<String>,
    /// API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
    pub key: Option<String>,
    /// OAuth 2.0 token for the current user.
    pub oauth_token: Option<String>,
    /// Returns response with indentations and line breaks.
    pub pretty_print: Option<bool>,
    /// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
    pub quota_user: Option<String>,
    /// Upload protocol for media (e.g. \"media\", \"multipart\", \"resumable\").
    pub upload_type: Option<String>,
    /// Deprecated. Please use quotaUser instead.
    pub user_ip: Option<String>,
    /// Makes the return of the bucket metadata conditional on whether the bucket's current metageneration matches the given value.
    pub if_metageneration_match: Option<String>,
    /// Makes the return of the bucket metadata conditional on whether the bucket's current metageneration does not match the given value.
    pub if_metageneration_not_match: Option<String>,
    /// Apply a predefined set of access controls to this bucket.
    pub predefined_acl: Option<String>,
    /// Apply a predefined set of default object access controls to this bucket.
    pub predefined_default_object_acl: Option<String>,
    /// Set of properties to return. Defaults to full.
    pub projection: Option<String>,
    /// The project to be billed for this request. Required for Requester Pays buckets.
    pub user_project: Option<String>,
    pub bucket2: Option<crate::google_rest_apis::storage_v1::models::Bucket>,
}

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

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

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

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

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

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

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

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

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

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

/// Permanently deletes an empty bucket.
pub async fn storage_buckets_delete(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodDeleteParams,
) -> Result<(), Error<StoragePeriodBucketsPeriodDeleteError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let if_metageneration_match = params.if_metageneration_match;
    let if_metageneration_not_match = params.if_metageneration_not_match;
    let user_project = params.user_project;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_match {
        local_var_req_builder =
            local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_not_match {
        local_var_req_builder = local_var_req_builder
            .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_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<StoragePeriodBucketsPeriodDeleteError> =
            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))
    }
}

/// Returns metadata for the specified bucket.
pub async fn storage_buckets_get(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodGetParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Bucket,
    Error<StoragePeriodBucketsPeriodGetError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let if_metageneration_match = params.if_metageneration_match;
    let if_metageneration_not_match = params.if_metageneration_not_match;
    let projection = params.projection;
    let user_project = params.user_project;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    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) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_match {
        local_var_req_builder =
            local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_not_match {
        local_var_req_builder = local_var_req_builder
            .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = projection {
        local_var_req_builder =
            local_var_req_builder.query(&[("projection", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_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<StoragePeriodBucketsPeriodGetError> =
            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))
    }
}

/// Returns an IAM policy for the specified bucket.
pub async fn storage_buckets_get_iam_policy(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodGetIamPolicyParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Policy,
    Error<StoragePeriodBucketsPeriodGetIamPolicyError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let options_requested_policy_version = params.options_requested_policy_version;
    let user_project = params.user_project;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}/iam",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    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) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = options_requested_policy_version {
        local_var_req_builder = local_var_req_builder
            .query(&[("optionsRequestedPolicyVersion", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_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<StoragePeriodBucketsPeriodGetIamPolicyError> =
            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))
    }
}

/// Creates a new bucket.
pub async fn storage_buckets_insert(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodInsertParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Bucket,
    Error<StoragePeriodBucketsPeriodInsertError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let project = params.project;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let predefined_acl = params.predefined_acl;
    let predefined_default_object_acl = params.predefined_default_object_acl;
    let projection = params.projection;
    let user_project = params.user_project;
    let bucket = params.bucket;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/b", local_var_configuration.base_path);
    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_str) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    local_var_req_builder = local_var_req_builder.query(&[("project", &project.to_string())]);
    if let Some(ref local_var_str) = predefined_acl {
        local_var_req_builder =
            local_var_req_builder.query(&[("predefinedAcl", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = predefined_default_object_acl {
        local_var_req_builder = local_var_req_builder
            .query(&[("predefinedDefaultObjectAcl", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = projection {
        local_var_req_builder =
            local_var_req_builder.query(&[("projection", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&bucket);

    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<StoragePeriodBucketsPeriodInsertError> =
            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))
    }
}

/// Retrieves a list of buckets for a given project.
pub async fn storage_buckets_list(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodListParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Buckets,
    Error<StoragePeriodBucketsPeriodListError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let project = params.project;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let max_results = params.max_results;
    let page_token = params.page_token;
    let prefix = params.prefix;
    let projection = params.projection;
    let user_project = params.user_project;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/b", local_var_configuration.base_path);
    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) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    local_var_req_builder = local_var_req_builder.query(&[("project", &project.to_string())]);
    if let Some(ref local_var_str) = max_results {
        local_var_req_builder =
            local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = page_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = prefix {
        local_var_req_builder =
            local_var_req_builder.query(&[("prefix", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = projection {
        local_var_req_builder =
            local_var_req_builder.query(&[("projection", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_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<StoragePeriodBucketsPeriodListError> =
            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))
    }
}

/// Locks retention policy on a bucket.
pub async fn storage_buckets_lock_retention_policy(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodLockRetentionPolicyParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Bucket,
    Error<StoragePeriodBucketsPeriodLockRetentionPolicyError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let if_metageneration_match = params.if_metageneration_match;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let user_project = params.user_project;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}/lockRetentionPolicy",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    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_str) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    local_var_req_builder = local_var_req_builder.query(&[(
        "ifMetagenerationMatch",
        &if_metageneration_match.to_string(),
    )]);
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_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<StoragePeriodBucketsPeriodLockRetentionPolicyError> =
            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))
    }
}

/// Patches a bucket. Changes to the bucket will be readable immediately after writing, but configuration changes may take time to propagate.
pub async fn storage_buckets_patch(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodPatchParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Bucket,
    Error<StoragePeriodBucketsPeriodPatchError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let if_metageneration_match = params.if_metageneration_match;
    let if_metageneration_not_match = params.if_metageneration_not_match;
    let predefined_acl = params.predefined_acl;
    let predefined_default_object_acl = params.predefined_default_object_acl;
    let projection = params.projection;
    let user_project = params.user_project;
    let bucket2 = params.bucket2;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_match {
        local_var_req_builder =
            local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_not_match {
        local_var_req_builder = local_var_req_builder
            .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = predefined_acl {
        local_var_req_builder =
            local_var_req_builder.query(&[("predefinedAcl", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = predefined_default_object_acl {
        local_var_req_builder = local_var_req_builder
            .query(&[("predefinedDefaultObjectAcl", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = projection {
        local_var_req_builder =
            local_var_req_builder.query(&[("projection", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&bucket2);

    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<StoragePeriodBucketsPeriodPatchError> =
            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))
    }
}

/// Updates an IAM policy for the specified bucket.
pub async fn storage_buckets_set_iam_policy(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodSetIamPolicyParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Policy,
    Error<StoragePeriodBucketsPeriodSetIamPolicyError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let user_project = params.user_project;
    let policy = params.policy;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}/iam",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&policy);

    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<StoragePeriodBucketsPeriodSetIamPolicyError> =
            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))
    }
}

/// Tests a set of permissions on the given bucket to see which, if any, are held by the caller.
pub async fn storage_buckets_test_iam_permissions(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodTestIamPermissionsParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::TestIamPermissionsResponse,
    Error<StoragePeriodBucketsPeriodTestIamPermissionsError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let permissions = params.permissions;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let user_project = params.user_project;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}/iam/testPermissions",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    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) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    local_var_req_builder = match "multi" {
        "multi" => local_var_req_builder.query(
            &permissions
                .into_iter()
                .map(|p| ("permissions".to_owned(), p.to_string()))
                .collect::<Vec<(std::string::String, std::string::String)>>(),
        ),
        _ => local_var_req_builder.query(&[(
            "permissions",
            &permissions
                .into_iter()
                .map(|p| p.to_string())
                .collect::<Vec<String>>()
                .join(",")
                .to_string(),
        )]),
    };
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_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<StoragePeriodBucketsPeriodTestIamPermissionsError> =
            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))
    }
}

/// Updates a bucket. Changes to the bucket will be readable immediately after writing, but configuration changes may take time to propagate.
pub async fn storage_buckets_update(
    configuration: &configuration::Configuration,
    params: StoragePeriodBucketsPeriodUpdateParams,
) -> Result<
    crate::google_rest_apis::storage_v1::models::Bucket,
    Error<StoragePeriodBucketsPeriodUpdateError>,
> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let bucket = params.bucket;
    let alt = params.alt;
    let fields = params.fields;
    let key = params.key;
    let oauth_token = params.oauth_token;
    let pretty_print = params.pretty_print;
    let quota_user = params.quota_user;
    let upload_type = params.upload_type;
    let user_ip = params.user_ip;
    let if_metageneration_match = params.if_metageneration_match;
    let if_metageneration_not_match = params.if_metageneration_not_match;
    let predefined_acl = params.predefined_acl;
    let predefined_default_object_acl = params.predefined_default_object_acl;
    let projection = params.projection;
    let user_project = params.user_project;
    let bucket2 = params.bucket2;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/b/{bucket}",
        local_var_configuration.base_path,
        bucket = crate::google_rest_apis::storage_v1::apis::urlencode(bucket)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = alt {
        local_var_req_builder = local_var_req_builder.query(&[("alt", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = fields {
        local_var_req_builder =
            local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = key {
        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = oauth_token {
        local_var_req_builder =
            local_var_req_builder.query(&[("oauth_token", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty_print {
        local_var_req_builder =
            local_var_req_builder.query(&[("prettyPrint", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = quota_user {
        local_var_req_builder =
            local_var_req_builder.query(&[("quotaUser", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = upload_type {
        local_var_req_builder =
            local_var_req_builder.query(&[("uploadType", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_ip {
        local_var_req_builder =
            local_var_req_builder.query(&[("userIp", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_match {
        local_var_req_builder =
            local_var_req_builder.query(&[("ifMetagenerationMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = if_metageneration_not_match {
        local_var_req_builder = local_var_req_builder
            .query(&[("ifMetagenerationNotMatch", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = predefined_acl {
        local_var_req_builder =
            local_var_req_builder.query(&[("predefinedAcl", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = predefined_default_object_acl {
        local_var_req_builder = local_var_req_builder
            .query(&[("predefinedDefaultObjectAcl", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = projection {
        local_var_req_builder =
            local_var_req_builder.query(&[("projection", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = user_project {
        local_var_req_builder =
            local_var_req_builder.query(&[("userProject", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&bucket2);

    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<StoragePeriodBucketsPeriodUpdateError> =
            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))
    }
}
