#![doc = "generated by AutoRust 0.1.0"]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(unused_imports)]
use crate::models::*;
use reqwest::StatusCode;
use snafu::{ResultExt, Snafu};
pub async fn list_operations(
    operation_config: &crate::OperationConfig,
) -> std::result::Result<SerialConsoleOperations, list_operations::Error> {
    let client = &operation_config.client;
    let uri_str = &format!("{}/providers/Microsoft.SerialConsole/operations", &operation_config.base_path,);
    let mut req_builder = client.get(uri_str);
    if let Some(token_credential) = &operation_config.token_credential {
        let token_response = token_credential
            .get_token(&operation_config.token_credential_resource)
            .await
            .context(list_operations::GetTokenError)?;
        req_builder = req_builder.bearer_auth(token_response.token.secret());
    }
    req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
    let req = req_builder.build().context(list_operations::BuildRequestError)?;
    let rsp = client.execute(req).await.context(list_operations::ExecuteRequestError)?;
    match rsp.status() {
        StatusCode::OK => {
            let body: bytes::Bytes = rsp.bytes().await.context(list_operations::ResponseBytesError)?;
            let rsp_value: SerialConsoleOperations = serde_json::from_slice(&body).context(list_operations::DeserializeError { body })?;
            Ok(rsp_value)
        }
        status_code => {
            let body: bytes::Bytes = rsp.bytes().await.context(list_operations::ResponseBytesError)?;
            list_operations::UnexpectedResponse { status_code, body: body }.fail()
        }
    }
}
pub mod list_operations {
    use crate::{models, models::*};
    use reqwest::StatusCode;
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        UnexpectedResponse { status_code: StatusCode, body: bytes::Bytes },
        BuildRequestError { source: reqwest::Error },
        ExecuteRequestError { source: reqwest::Error },
        ResponseBytesError { source: reqwest::Error },
        DeserializeError { source: serde_json::Error, body: bytes::Bytes },
        GetTokenError { source: azure_core::errors::AzureError },
    }
}
pub async fn get_console_status(
    operation_config: &crate::OperationConfig,
    subscription_id: &str,
    default: &str,
) -> std::result::Result<SerialConsoleStatus, get_console_status::Error> {
    let client = &operation_config.client;
    let uri_str = &format!(
        "{}/subscriptions/{}/providers/Microsoft.SerialConsole/consoleServices/{}",
        &operation_config.base_path, subscription_id, default
    );
    let mut req_builder = client.get(uri_str);
    if let Some(token_credential) = &operation_config.token_credential {
        let token_response = token_credential
            .get_token(&operation_config.token_credential_resource)
            .await
            .context(get_console_status::GetTokenError)?;
        req_builder = req_builder.bearer_auth(token_response.token.secret());
    }
    req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
    let req = req_builder.build().context(get_console_status::BuildRequestError)?;
    let rsp = client.execute(req).await.context(get_console_status::ExecuteRequestError)?;
    match rsp.status() {
        StatusCode::OK => {
            let body: bytes::Bytes = rsp.bytes().await.context(get_console_status::ResponseBytesError)?;
            let rsp_value: SerialConsoleStatus = serde_json::from_slice(&body).context(get_console_status::DeserializeError { body })?;
            Ok(rsp_value)
        }
        StatusCode::NOT_FOUND => {
            let body: bytes::Bytes = rsp.bytes().await.context(get_console_status::ResponseBytesError)?;
            let rsp_value: GetSerialConsoleSubscriptionNotFound =
                serde_json::from_slice(&body).context(get_console_status::DeserializeError { body })?;
            get_console_status::NotFound404 { value: rsp_value }.fail()
        }
        status_code => {
            let body: bytes::Bytes = rsp.bytes().await.context(get_console_status::ResponseBytesError)?;
            get_console_status::UnexpectedResponse { status_code, body: body }.fail()
        }
    }
}
pub mod get_console_status {
    use crate::{models, models::*};
    use reqwest::StatusCode;
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        NotFound404 {
            value: models::GetSerialConsoleSubscriptionNotFound,
        },
        UnexpectedResponse {
            status_code: StatusCode,
            body: bytes::Bytes,
        },
        BuildRequestError {
            source: reqwest::Error,
        },
        ExecuteRequestError {
            source: reqwest::Error,
        },
        ResponseBytesError {
            source: reqwest::Error,
        },
        DeserializeError {
            source: serde_json::Error,
            body: bytes::Bytes,
        },
        GetTokenError {
            source: azure_core::errors::AzureError,
        },
    }
}
pub async fn disable_console(
    operation_config: &crate::OperationConfig,
    subscription_id: &str,
    default: &str,
) -> std::result::Result<DisableSerialConsoleResult, disable_console::Error> {
    let client = &operation_config.client;
    let uri_str = &format!(
        "{}/subscriptions/{}/providers/Microsoft.SerialConsole/consoleServices/{}/disableConsole",
        &operation_config.base_path, subscription_id, default
    );
    let mut req_builder = client.post(uri_str);
    if let Some(token_credential) = &operation_config.token_credential {
        let token_response = token_credential
            .get_token(&operation_config.token_credential_resource)
            .await
            .context(disable_console::GetTokenError)?;
        req_builder = req_builder.bearer_auth(token_response.token.secret());
    }
    req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
    req_builder = req_builder.header(reqwest::header::CONTENT_LENGTH, 0);
    let req = req_builder.build().context(disable_console::BuildRequestError)?;
    let rsp = client.execute(req).await.context(disable_console::ExecuteRequestError)?;
    match rsp.status() {
        StatusCode::OK => {
            let body: bytes::Bytes = rsp.bytes().await.context(disable_console::ResponseBytesError)?;
            let rsp_value: DisableSerialConsoleResult =
                serde_json::from_slice(&body).context(disable_console::DeserializeError { body })?;
            Ok(rsp_value)
        }
        StatusCode::NOT_FOUND => {
            let body: bytes::Bytes = rsp.bytes().await.context(disable_console::ResponseBytesError)?;
            let rsp_value: GetSerialConsoleSubscriptionNotFound =
                serde_json::from_slice(&body).context(disable_console::DeserializeError { body })?;
            disable_console::NotFound404 { value: rsp_value }.fail()
        }
        status_code => {
            let body: bytes::Bytes = rsp.bytes().await.context(disable_console::ResponseBytesError)?;
            disable_console::UnexpectedResponse { status_code, body: body }.fail()
        }
    }
}
pub mod disable_console {
    use crate::{models, models::*};
    use reqwest::StatusCode;
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        NotFound404 {
            value: models::GetSerialConsoleSubscriptionNotFound,
        },
        UnexpectedResponse {
            status_code: StatusCode,
            body: bytes::Bytes,
        },
        BuildRequestError {
            source: reqwest::Error,
        },
        ExecuteRequestError {
            source: reqwest::Error,
        },
        ResponseBytesError {
            source: reqwest::Error,
        },
        DeserializeError {
            source: serde_json::Error,
            body: bytes::Bytes,
        },
        GetTokenError {
            source: azure_core::errors::AzureError,
        },
    }
}
pub async fn enable_console(
    operation_config: &crate::OperationConfig,
    subscription_id: &str,
    default: &str,
) -> std::result::Result<EnableSerialConsoleResult, enable_console::Error> {
    let client = &operation_config.client;
    let uri_str = &format!(
        "{}/subscriptions/{}/providers/Microsoft.SerialConsole/consoleServices/{}/enableConsole",
        &operation_config.base_path, subscription_id, default
    );
    let mut req_builder = client.post(uri_str);
    if let Some(token_credential) = &operation_config.token_credential {
        let token_response = token_credential
            .get_token(&operation_config.token_credential_resource)
            .await
            .context(enable_console::GetTokenError)?;
        req_builder = req_builder.bearer_auth(token_response.token.secret());
    }
    req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
    req_builder = req_builder.header(reqwest::header::CONTENT_LENGTH, 0);
    let req = req_builder.build().context(enable_console::BuildRequestError)?;
    let rsp = client.execute(req).await.context(enable_console::ExecuteRequestError)?;
    match rsp.status() {
        StatusCode::OK => {
            let body: bytes::Bytes = rsp.bytes().await.context(enable_console::ResponseBytesError)?;
            let rsp_value: EnableSerialConsoleResult = serde_json::from_slice(&body).context(enable_console::DeserializeError { body })?;
            Ok(rsp_value)
        }
        StatusCode::NOT_FOUND => {
            let body: bytes::Bytes = rsp.bytes().await.context(enable_console::ResponseBytesError)?;
            let rsp_value: GetSerialConsoleSubscriptionNotFound =
                serde_json::from_slice(&body).context(enable_console::DeserializeError { body })?;
            enable_console::NotFound404 { value: rsp_value }.fail()
        }
        status_code => {
            let body: bytes::Bytes = rsp.bytes().await.context(enable_console::ResponseBytesError)?;
            enable_console::UnexpectedResponse { status_code, body: body }.fail()
        }
    }
}
pub mod enable_console {
    use crate::{models, models::*};
    use reqwest::StatusCode;
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        NotFound404 {
            value: models::GetSerialConsoleSubscriptionNotFound,
        },
        UnexpectedResponse {
            status_code: StatusCode,
            body: bytes::Bytes,
        },
        BuildRequestError {
            source: reqwest::Error,
        },
        ExecuteRequestError {
            source: reqwest::Error,
        },
        ResponseBytesError {
            source: reqwest::Error,
        },
        DeserializeError {
            source: serde_json::Error,
            body: bytes::Bytes,
        },
        GetTokenError {
            source: azure_core::errors::AzureError,
        },
    }
}
