#[derive(Debug)]
pub struct ApiClient<'a> {
    base_client: &'a mut crate::core::base_client::BaseClient,
}
impl<'a> ApiClient<'a> {
    pub(crate) fn _new(
        base_client: &'a mut crate::core::base_client::BaseClient,
    ) -> Self {
        Self { base_client }
    }
    pub fn spec(&mut self) -> crate::resources::api::spec::resource_client::SpecClient {
        crate::resources::api::spec::resource_client::SpecClient::_new(self.base_client)
    }
    /// Delete an API
    ///
    /// DELETE /api/{api_name}
    pub async fn delete(
        &mut self,
        request: super::request_types::DeleteRequest,
    ) -> crate::SdkResult<()> {
        let url = self
            .base_client
            .build_url(
                &format!(
                    "/api/{}", crate ::core::params::format_string_param(& request
                    .api_name)
                ),
            );
        let mut builder = reqwest::Client::default().delete(&url);
        builder = builder.header("x-sideko-sdk-language", "rust");
        builder = self
            .base_client
            .apply_auths_to_builder(builder, &["ApiKeyAuth", "CookieAuth"])
            .await?;
        let response = builder.send().await?;
        self.base_client.error_for_status("DELETE", response).await?;
        Ok(())
    }
    /// List your APIs
    ///
    /// GET /api
    pub async fn list(&mut self) -> crate::SdkResult<Vec<crate::models::Api>> {
        let url = self.base_client.build_url("/api");
        let mut builder = reqwest::Client::default().get(&url);
        builder = builder.header("x-sideko-sdk-language", "rust");
        builder = self
            .base_client
            .apply_auths_to_builder(builder, &["ApiKeyAuth", "CookieAuth"])
            .await?;
        let mut response = builder.send().await?;
        response = self.base_client.error_for_status("GET", response).await?;
        crate::core::response::process_json::<Vec<crate::models::Api>>(response).await
    }
    /// Get one API
    ///
    /// GET /api/{api_name}
    pub async fn get(
        &mut self,
        request: super::request_types::GetRequest,
    ) -> crate::SdkResult<crate::models::Api> {
        let url = self
            .base_client
            .build_url(
                &format!(
                    "/api/{}", crate ::core::params::format_string_param(& request
                    .api_name)
                ),
            );
        let mut builder = reqwest::Client::default().get(&url);
        builder = builder.header("x-sideko-sdk-language", "rust");
        builder = self
            .base_client
            .apply_auths_to_builder(builder, &["ApiKeyAuth", "CookieAuth"])
            .await?;
        let mut response = builder.send().await?;
        response = self.base_client.error_for_status("GET", response).await?;
        crate::core::response::process_json::<crate::models::Api>(response).await
    }
    /// Update an existing API
    ///
    /// PATCH /api/{api_name}
    pub async fn patch(
        &mut self,
        request: super::request_types::PatchRequest,
    ) -> crate::SdkResult<crate::models::Api> {
        let url = self
            .base_client
            .build_url(
                &format!(
                    "/api/{}", crate ::core::params::format_string_param(& request
                    .api_name)
                ),
            );
        let mut builder = reqwest::Client::default().patch(&url);
        builder = builder.header("x-sideko-sdk-language", "rust");
        builder = builder.header("content-type", "application/json");
        builder = builder
            .json(
                &crate::models::UpdateApi {
                    name: request.name,
                },
            );
        builder = self
            .base_client
            .apply_auths_to_builder(builder, &["ApiKeyAuth", "CookieAuth"])
            .await?;
        let mut response = builder.send().await?;
        response = self.base_client.error_for_status("PATCH", response).await?;
        crate::core::response::process_json::<crate::models::Api>(response).await
    }
    /// Create a new API
    ///
    /// POST /api
    pub async fn create(
        &mut self,
        request: super::request_types::CreateRequest,
    ) -> crate::SdkResult<crate::models::Api> {
        let url = self.base_client.build_url("/api");
        let mut builder = reqwest::Client::default().post(&url);
        builder = builder.header("x-sideko-sdk-language", "rust");
        builder = builder.header("content-type", "application/json");
        builder = builder
            .json(
                &crate::models::NewApi {
                    name: request.name,
                },
            );
        builder = self
            .base_client
            .apply_auths_to_builder(builder, &["ApiKeyAuth", "CookieAuth"])
            .await?;
        let mut response = builder.send().await?;
        response = self.base_client.error_for_status("POST", response).await?;
        crate::core::response::process_json::<crate::models::Api>(response).await
    }
    /// Create an API with an initial version
    ///
    /// POST /api/init
    pub async fn init(
        &mut self,
        request: super::request_types::InitRequest,
    ) -> crate::SdkResult<crate::models::ApiSpec> {
        let url = self.base_client.build_url("/api/init");
        let mut builder = reqwest::Client::default().post(&url);
        builder = builder.header("x-sideko-sdk-language", "rust");
        let mut form_data = reqwest::multipart::Form::new();
        if let Some(val) = &request.allow_lint_errors {
            form_data = form_data
                .part(
                    "allow_lint_errors",
                    reqwest::multipart::Part::text(
                        crate::core::params::format_string_param(&val),
                    ),
                );
        }
        if let Some(val) = &request.mock_server_enabled {
            form_data = form_data
                .part(
                    "mock_server_enabled",
                    reqwest::multipart::Part::text(
                        crate::core::params::format_string_param(&val),
                    ),
                );
        }
        if let Some(val) = &request.notes {
            form_data = form_data
                .part(
                    "notes",
                    reqwest::multipart::Part::text(
                        crate::core::params::format_string_param(&val),
                    ),
                );
        }
        form_data = form_data
            .part(
                "name",
                reqwest::multipart::Part::text(
                    crate::core::params::format_string_param(&request.name),
                ),
            );
        form_data = form_data
            .part("openapi", reqwest::multipart::Part::from(&request.openapi));
        form_data = form_data
            .part(
                "version",
                reqwest::multipart::Part::text(
                    crate::core::params::format_string_param(&request.version),
                ),
            );
        builder = builder.multipart(form_data);
        builder = self
            .base_client
            .apply_auths_to_builder(builder, &["ApiKeyAuth", "CookieAuth"])
            .await?;
        let mut response = builder.send().await?;
        response = self.base_client.error_for_status("POST", response).await?;
        crate::core::response::process_json::<crate::models::ApiSpec>(response).await
    }
}
