// Code generated by oagen. DO NOT EDIT.

use crate::client::Retab;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;

pub struct SecretsApi<'a> {
    pub(crate) client: &'a Retab,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateSecretParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: CreateSecretRequest,
}

impl CreateSecretParams {
    /// Construct a new `CreateSecretParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: CreateSecretRequest) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct UpdateSecretParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: SetSecretRequest,
}

impl UpdateSecretParams {
    /// Construct a new `UpdateSecretParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: SetSecretRequest) -> Self {
        Self { body }
    }
}

impl<'a> SecretsApi<'a> {
    /// List Secrets
    pub async fn list_secrets(&self) -> Result<SecretListResponse, Error> {
        self.list_secrets_with_options(None).await
    }

    /// Variant of [`Self::list_secrets`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_secrets_with_options(
        &self,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SecretListResponse, Error> {
        let path = "/v1/secrets".to_string();
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Create Secret
    pub async fn create_secret(&self, params: CreateSecretParams) -> Result<SecretResponse, Error> {
        self.create_secret_with_options(params, None).await
    }

    /// Variant of [`Self::create_secret`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_secret_with_options(
        &self,
        params: CreateSecretParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SecretResponse, Error> {
        let path = "/v1/secrets".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Secret
    pub async fn get_secret(&self, name: &str) -> Result<SecretResponse, Error> {
        self.get_secret_with_options(name, None).await
    }

    /// Variant of [`Self::get_secret`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_secret_with_options(
        &self,
        name: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SecretResponse, Error> {
        let name = crate::client::path_segment(name);
        let path = format!("/v1/secrets/{name}");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Set Secret
    pub async fn update_secret(
        &self,
        name: &str,
        params: UpdateSecretParams,
    ) -> Result<SecretResponse, Error> {
        self.update_secret_with_options(name, params, None).await
    }

    /// Variant of [`Self::update_secret`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_secret_with_options(
        &self,
        name: &str,
        params: UpdateSecretParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SecretResponse, Error> {
        let name = crate::client::path_segment(name);
        let path = format!("/v1/secrets/{name}");
        let method = http::Method::PUT;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Delete Secret
    pub async fn delete_secret(&self, name: &str) -> Result<(), Error> {
        self.delete_secret_with_options(name, None).await
    }

    /// Variant of [`Self::delete_secret`] that accepts per-request [`crate::RequestOptions`].
    pub async fn delete_secret_with_options(
        &self,
        name: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<(), Error> {
        let name = crate::client::path_segment(name);
        let path = format!("/v1/secrets/{name}");
        let method = http::Method::DELETE;
        self.client
            .request_with_query_opts_empty(method, &path, &(), options)
            .await
    }

    /// Get Secret Value
    pub async fn list_secret_value(&self, name: &str) -> Result<SecretValueResponse, Error> {
        self.list_secret_value_with_options(name, None).await
    }

    /// Variant of [`Self::list_secret_value`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_secret_value_with_options(
        &self,
        name: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SecretValueResponse, Error> {
        let name = crate::client::path_segment(name);
        let path = format!("/v1/secrets/{name}/value");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }
}
