#![doc = "generated by AutoRust 0.1.0"]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(unused_imports)]
use crate::models::*;
use snafu::{ResultExt, Snafu};
pub async fn resources(
    operation_config: &crate::OperationConfig,
    query: &QueryRequest,
) -> std::result::Result<QueryResponse, resources::Error> {
    let http_client = operation_config.http_client();
    let url_str = &format!("{}/providers/Microsoft.ResourceGraph/resources", operation_config.base_path(),);
    let mut url = url::Url::parse(url_str).context(resources::ParseUrlError)?;
    let mut req_builder = http::request::Builder::new();
    req_builder = req_builder.method(http::Method::POST);
    if let Some(token_credential) = operation_config.token_credential() {
        let token_response = token_credential
            .get_token(operation_config.token_credential_resource())
            .await
            .context(resources::GetTokenError)?;
        req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
    }
    url.query_pairs_mut().append_pair("api-version", operation_config.api_version());
    let req_body = azure_core::to_json(query).context(resources::SerializeError)?;
    req_builder = req_builder.uri(url.as_str());
    let req = req_builder.body(req_body).context(resources::BuildRequestError)?;
    let rsp = http_client.execute_request(req).await.context(resources::ExecuteRequestError)?;
    match rsp.status() {
        http::StatusCode::OK => {
            let rsp_body = rsp.body();
            let rsp_value: QueryResponse =
                serde_json::from_slice(rsp_body).context(resources::DeserializeError { body: rsp_body.clone() })?;
            Ok(rsp_value)
        }
        status_code => {
            let rsp_body = rsp.body();
            let rsp_value: ErrorResponse =
                serde_json::from_slice(rsp_body).context(resources::DeserializeError { body: rsp_body.clone() })?;
            resources::DefaultResponse {
                status_code,
                value: rsp_value,
            }
            .fail()
        }
    }
}
pub mod resources {
    use crate::{models, models::*};
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        DefaultResponse {
            status_code: http::StatusCode,
            value: models::ErrorResponse,
        },
        ParseUrlError {
            source: url::ParseError,
        },
        BuildRequestError {
            source: http::Error,
        },
        ExecuteRequestError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        SerializeError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        DeserializeError {
            source: serde_json::Error,
            body: bytes::Bytes,
        },
        GetTokenError {
            source: azure_core::errors::AzureError,
        },
    }
}
pub async fn resource_changes(
    operation_config: &crate::OperationConfig,
    parameters: &ResourceChangesRequestParameters,
) -> std::result::Result<ResourceChangeList, resource_changes::Error> {
    let http_client = operation_config.http_client();
    let url_str = &format!("{}/providers/Microsoft.ResourceGraph/resourceChanges", operation_config.base_path(),);
    let mut url = url::Url::parse(url_str).context(resource_changes::ParseUrlError)?;
    let mut req_builder = http::request::Builder::new();
    req_builder = req_builder.method(http::Method::POST);
    if let Some(token_credential) = operation_config.token_credential() {
        let token_response = token_credential
            .get_token(operation_config.token_credential_resource())
            .await
            .context(resource_changes::GetTokenError)?;
        req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
    }
    url.query_pairs_mut().append_pair("api-version", operation_config.api_version());
    let req_body = azure_core::to_json(parameters).context(resource_changes::SerializeError)?;
    req_builder = req_builder.uri(url.as_str());
    let req = req_builder.body(req_body).context(resource_changes::BuildRequestError)?;
    let rsp = http_client
        .execute_request(req)
        .await
        .context(resource_changes::ExecuteRequestError)?;
    match rsp.status() {
        http::StatusCode::OK => {
            let rsp_body = rsp.body();
            let rsp_value: ResourceChangeList =
                serde_json::from_slice(rsp_body).context(resource_changes::DeserializeError { body: rsp_body.clone() })?;
            Ok(rsp_value)
        }
        status_code => {
            let rsp_body = rsp.body();
            let rsp_value: ErrorResponse =
                serde_json::from_slice(rsp_body).context(resource_changes::DeserializeError { body: rsp_body.clone() })?;
            resource_changes::DefaultResponse {
                status_code,
                value: rsp_value,
            }
            .fail()
        }
    }
}
pub mod resource_changes {
    use crate::{models, models::*};
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        DefaultResponse {
            status_code: http::StatusCode,
            value: models::ErrorResponse,
        },
        ParseUrlError {
            source: url::ParseError,
        },
        BuildRequestError {
            source: http::Error,
        },
        ExecuteRequestError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        SerializeError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        DeserializeError {
            source: serde_json::Error,
            body: bytes::Bytes,
        },
        GetTokenError {
            source: azure_core::errors::AzureError,
        },
    }
}
pub async fn resource_change_details(
    operation_config: &crate::OperationConfig,
    parameters: &ResourceChangeDetailsRequestParameters,
) -> std::result::Result<ResourceChangeData, resource_change_details::Error> {
    let http_client = operation_config.http_client();
    let url_str = &format!(
        "{}/providers/Microsoft.ResourceGraph/resourceChangeDetails",
        operation_config.base_path(),
    );
    let mut url = url::Url::parse(url_str).context(resource_change_details::ParseUrlError)?;
    let mut req_builder = http::request::Builder::new();
    req_builder = req_builder.method(http::Method::POST);
    if let Some(token_credential) = operation_config.token_credential() {
        let token_response = token_credential
            .get_token(operation_config.token_credential_resource())
            .await
            .context(resource_change_details::GetTokenError)?;
        req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
    }
    url.query_pairs_mut().append_pair("api-version", operation_config.api_version());
    let req_body = azure_core::to_json(parameters).context(resource_change_details::SerializeError)?;
    req_builder = req_builder.uri(url.as_str());
    let req = req_builder.body(req_body).context(resource_change_details::BuildRequestError)?;
    let rsp = http_client
        .execute_request(req)
        .await
        .context(resource_change_details::ExecuteRequestError)?;
    match rsp.status() {
        http::StatusCode::OK => {
            let rsp_body = rsp.body();
            let rsp_value: ResourceChangeData =
                serde_json::from_slice(rsp_body).context(resource_change_details::DeserializeError { body: rsp_body.clone() })?;
            Ok(rsp_value)
        }
        status_code => {
            let rsp_body = rsp.body();
            let rsp_value: ErrorResponse =
                serde_json::from_slice(rsp_body).context(resource_change_details::DeserializeError { body: rsp_body.clone() })?;
            resource_change_details::DefaultResponse {
                status_code,
                value: rsp_value,
            }
            .fail()
        }
    }
}
pub mod resource_change_details {
    use crate::{models, models::*};
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        DefaultResponse {
            status_code: http::StatusCode,
            value: models::ErrorResponse,
        },
        ParseUrlError {
            source: url::ParseError,
        },
        BuildRequestError {
            source: http::Error,
        },
        ExecuteRequestError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        SerializeError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        DeserializeError {
            source: serde_json::Error,
            body: bytes::Bytes,
        },
        GetTokenError {
            source: azure_core::errors::AzureError,
        },
    }
}
pub async fn resources_history(
    operation_config: &crate::OperationConfig,
    request: &ResourcesHistoryRequest,
) -> std::result::Result<serde_json::Value, resources_history::Error> {
    let http_client = operation_config.http_client();
    let url_str = &format!(
        "{}/providers/Microsoft.ResourceGraph/resourcesHistory",
        operation_config.base_path(),
    );
    let mut url = url::Url::parse(url_str).context(resources_history::ParseUrlError)?;
    let mut req_builder = http::request::Builder::new();
    req_builder = req_builder.method(http::Method::POST);
    if let Some(token_credential) = operation_config.token_credential() {
        let token_response = token_credential
            .get_token(operation_config.token_credential_resource())
            .await
            .context(resources_history::GetTokenError)?;
        req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
    }
    url.query_pairs_mut().append_pair("api-version", operation_config.api_version());
    let req_body = azure_core::to_json(request).context(resources_history::SerializeError)?;
    req_builder = req_builder.uri(url.as_str());
    let req = req_builder.body(req_body).context(resources_history::BuildRequestError)?;
    let rsp = http_client
        .execute_request(req)
        .await
        .context(resources_history::ExecuteRequestError)?;
    match rsp.status() {
        http::StatusCode::OK => {
            let rsp_body = rsp.body();
            let rsp_value: serde_json::Value =
                serde_json::from_slice(rsp_body).context(resources_history::DeserializeError { body: rsp_body.clone() })?;
            Ok(rsp_value)
        }
        status_code => {
            let rsp_body = rsp.body();
            let rsp_value: ErrorResponse =
                serde_json::from_slice(rsp_body).context(resources_history::DeserializeError { body: rsp_body.clone() })?;
            resources_history::DefaultResponse {
                status_code,
                value: rsp_value,
            }
            .fail()
        }
    }
}
pub mod resources_history {
    use crate::{models, models::*};
    use snafu::Snafu;
    #[derive(Debug, Snafu)]
    #[snafu(visibility(pub(crate)))]
    pub enum Error {
        DefaultResponse {
            status_code: http::StatusCode,
            value: models::ErrorResponse,
        },
        ParseUrlError {
            source: url::ParseError,
        },
        BuildRequestError {
            source: http::Error,
        },
        ExecuteRequestError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        SerializeError {
            source: Box<dyn std::error::Error + Sync + Send>,
        },
        DeserializeError {
            source: serde_json::Error,
            body: bytes::Bytes,
        },
        GetTokenError {
            source: azure_core::errors::AzureError,
        },
    }
}
pub mod operations {
    use crate::models::*;
    use snafu::{ResultExt, Snafu};
    pub async fn list(operation_config: &crate::OperationConfig) -> std::result::Result<OperationListResult, list::Error> {
        let http_client = operation_config.http_client();
        let url_str = &format!("{}/providers/Microsoft.ResourceGraph/operations", operation_config.base_path(),);
        let mut url = url::Url::parse(url_str).context(list::ParseUrlError)?;
        let mut req_builder = http::request::Builder::new();
        req_builder = req_builder.method(http::Method::GET);
        if let Some(token_credential) = operation_config.token_credential() {
            let token_response = token_credential
                .get_token(operation_config.token_credential_resource())
                .await
                .context(list::GetTokenError)?;
            req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret()));
        }
        url.query_pairs_mut().append_pair("api-version", operation_config.api_version());
        let req_body = bytes::Bytes::from_static(azure_core::EMPTY_BODY);
        req_builder = req_builder.uri(url.as_str());
        let req = req_builder.body(req_body).context(list::BuildRequestError)?;
        let rsp = http_client.execute_request(req).await.context(list::ExecuteRequestError)?;
        match rsp.status() {
            http::StatusCode::OK => {
                let rsp_body = rsp.body();
                let rsp_value: OperationListResult =
                    serde_json::from_slice(rsp_body).context(list::DeserializeError { body: rsp_body.clone() })?;
                Ok(rsp_value)
            }
            status_code => {
                let rsp_body = rsp.body();
                let rsp_value: ErrorResponse =
                    serde_json::from_slice(rsp_body).context(list::DeserializeError { body: rsp_body.clone() })?;
                list::DefaultResponse {
                    status_code,
                    value: rsp_value,
                }
                .fail()
            }
        }
    }
    pub mod list {
        use crate::{models, models::*};
        use snafu::Snafu;
        #[derive(Debug, Snafu)]
        #[snafu(visibility(pub(crate)))]
        pub enum Error {
            DefaultResponse {
                status_code: http::StatusCode,
                value: models::ErrorResponse,
            },
            ParseUrlError {
                source: url::ParseError,
            },
            BuildRequestError {
                source: http::Error,
            },
            ExecuteRequestError {
                source: Box<dyn std::error::Error + Sync + Send>,
            },
            SerializeError {
                source: Box<dyn std::error::Error + Sync + Send>,
            },
            DeserializeError {
                source: serde_json::Error,
                body: bytes::Bytes,
            },
            GetTokenError {
                source: azure_core::errors::AzureError,
            },
        }
    }
}
