/*
 * Binance Mining REST API
 *
 * OpenAPI Specification for the Binance Mining REST API
 *
 * The version of the OpenAPI document: 1.0.0
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

#![allow(unused_imports)]
use http::Method;
use serde::de::DeserializeOwned;
use serde_json::Value;
use std::collections::BTreeMap;

use crate::common::{config::ConfigurationRestApi, models::RestApiResponse, utils::send_request};

mod apis;
mod models;

pub use apis::*;
pub use models::*;

#[derive(Debug, Clone)]
pub struct RestApi {
    configuration: ConfigurationRestApi,
    mining_api_client: MiningApiClient,
}

impl RestApi {
    pub fn new(configuration: ConfigurationRestApi) -> Self {
        let mining_api_client = MiningApiClient::new(configuration.clone());

        Self {
            configuration,
            mining_api_client,
        }
    }

    /// Send an unsigned request to the API
    ///
    /// # Arguments
    ///
    /// * `endpoint` - The API endpoint to send the request to
    /// * `method` - The HTTP method to use for the request
    /// * `query_params` - A map of query parameters to send with the request
    /// * `body_params` - A map of body parameters to send with the request
    ///
    /// # Returns
    ///
    /// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
    ///
    /// # Errors
    ///
    /// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
    pub async fn send_request<R: DeserializeOwned + Send + 'static>(
        &self,
        endpoint: &str,
        method: Method,
        query_params: BTreeMap<String, Value>,
        body_params: BTreeMap<String, Value>,
    ) -> anyhow::Result<RestApiResponse<R>> {
        send_request::<R>(
            &self.configuration,
            endpoint,
            method,
            query_params,
            body_params,
            None,
            false,
        )
        .await
    }

    /// Send a signed request to the API
    ///
    /// # Arguments
    ///
    /// * `endpoint` - The API endpoint to send the request to
    /// * `method` - The HTTP method to use for the request
    /// * `query_params` - A map of query parameters to send with the request
    /// * `body_params` - A map of body parameters to send with the request
    ///
    /// # Returns
    ///
    /// A `RestApiResponse` containing the deserialized response data on success, or an error if the request fails
    ///
    /// # Errors
    ///
    /// Returns an `anyhow::Error` if the HTTP request fails or if parsing the response fails
    pub async fn send_signed_request<R: DeserializeOwned + Send + 'static>(
        &self,
        endpoint: &str,
        method: Method,
        query_params: BTreeMap<String, Value>,
        body_params: BTreeMap<String, Value>,
    ) -> anyhow::Result<RestApiResponse<R>> {
        send_request::<R>(
            &self.configuration,
            endpoint,
            method,
            query_params,
            body_params,
            None,
            true,
        )
        .await
    }

    /// Account `List(USER_DATA)`
    ///
    /// Query Account List
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`AccountListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::AccountListResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Account-List).
    ///
    pub async fn account_list(
        &self,
        params: AccountListParams,
    ) -> anyhow::Result<RestApiResponse<models::AccountListResponse>> {
        self.mining_api_client.account_list(params).await
    }

    /// Acquiring `Algorithm(MARKET_DATA)`
    ///
    /// Acquiring Algorithm
    ///
    /// Weight: 1
    ///
    /// # Arguments
    ///
    /// - `params`: [`AcquiringAlgorithmParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::AcquiringAlgorithmResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Acquiring-Algorithm).
    ///
    pub async fn acquiring_algorithm(
        &self,
    ) -> anyhow::Result<RestApiResponse<models::AcquiringAlgorithmResponse>> {
        self.mining_api_client.acquiring_algorithm().await
    }

    /// Acquiring `CoinName(MARKET_DATA)`
    ///
    /// Acquiring `CoinName`
    ///
    /// Weight: 1
    ///
    /// # Arguments
    ///
    /// - `params`: [`AcquiringCoinnameParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::AcquiringCoinnameResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Acquiring-CoinName).
    ///
    pub async fn acquiring_coinname(
        &self,
    ) -> anyhow::Result<RestApiResponse<models::AcquiringCoinnameResponse>> {
        self.mining_api_client.acquiring_coinname().await
    }

    /// Cancel hashrate resale `configuration(USER_DATA)`
    ///
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`CancelHashrateResaleConfigurationParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::CancelHashrateResaleConfigurationResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Cancel-hashrate-resale-configuration).
    ///
    pub async fn cancel_hashrate_resale_configuration(
        &self,
        params: CancelHashrateResaleConfigurationParams,
    ) -> anyhow::Result<RestApiResponse<models::CancelHashrateResaleConfigurationResponse>> {
        self.mining_api_client
            .cancel_hashrate_resale_configuration(params)
            .await
    }

    /// Earnings `List(USER_DATA)`
    ///
    /// Query Earnings List
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`EarningsListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::EarningsListResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Earnings-List).
    ///
    pub async fn earnings_list(
        &self,
        params: EarningsListParams,
    ) -> anyhow::Result<RestApiResponse<models::EarningsListResponse>> {
        self.mining_api_client.earnings_list(params).await
    }

    /// Extra Bonus `List(USER_DATA)`
    ///
    /// Extra Bonus List
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`ExtraBonusListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::ExtraBonusListResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Extra-Bonus-List).
    ///
    pub async fn extra_bonus_list(
        &self,
        params: ExtraBonusListParams,
    ) -> anyhow::Result<RestApiResponse<models::ExtraBonusListResponse>> {
        self.mining_api_client.extra_bonus_list(params).await
    }

    /// Hashrate Resale `Detail(USER_DATA)`
    ///
    /// Hashrate Resale `Detail(USER_DATA)`
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`HashrateResaleDetailParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::HashrateResaleDetailResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Detail).
    ///
    pub async fn hashrate_resale_detail(
        &self,
        params: HashrateResaleDetailParams,
    ) -> anyhow::Result<RestApiResponse<models::HashrateResaleDetailResponse>> {
        self.mining_api_client.hashrate_resale_detail(params).await
    }

    /// Hashrate Resale List
    ///
    /// Hashrate Resale List
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`HashrateResaleListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::HashrateResaleListResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-List).
    ///
    pub async fn hashrate_resale_list(
        &self,
        params: HashrateResaleListParams,
    ) -> anyhow::Result<RestApiResponse<models::HashrateResaleListResponse>> {
        self.mining_api_client.hashrate_resale_list(params).await
    }

    /// Hashrate Resale `Request(USER_DATA)`
    ///
    /// Hashrate Resale Request
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`HashrateResaleRequestParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::HashrateResaleRequestResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Request).
    ///
    pub async fn hashrate_resale_request(
        &self,
        params: HashrateResaleRequestParams,
    ) -> anyhow::Result<RestApiResponse<models::HashrateResaleRequestResponse>> {
        self.mining_api_client.hashrate_resale_request(params).await
    }

    /// Mining Account `Earning(USER_DATA)`
    ///
    /// Mining Account Earning
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`MiningAccountEarningParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::MiningAccountEarningResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Mining-Account-Earning).
    ///
    pub async fn mining_account_earning(
        &self,
        params: MiningAccountEarningParams,
    ) -> anyhow::Result<RestApiResponse<models::MiningAccountEarningResponse>> {
        self.mining_api_client.mining_account_earning(params).await
    }

    /// Request for Detail Miner `List(USER_DATA)`
    ///
    /// Request for Detail Miner List
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`RequestForDetailMinerListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::RequestForDetailMinerListResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Request-for-Detail-Miner-List).
    ///
    pub async fn request_for_detail_miner_list(
        &self,
        params: RequestForDetailMinerListParams,
    ) -> anyhow::Result<RestApiResponse<models::RequestForDetailMinerListResponse>> {
        self.mining_api_client
            .request_for_detail_miner_list(params)
            .await
    }

    /// Request for Miner `List(USER_DATA)`
    ///
    /// Request for Miner List
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`RequestForMinerListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::RequestForMinerListResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Request-for-Miner-List).
    ///
    pub async fn request_for_miner_list(
        &self,
        params: RequestForMinerListParams,
    ) -> anyhow::Result<RestApiResponse<models::RequestForMinerListResponse>> {
        self.mining_api_client.request_for_miner_list(params).await
    }

    /// Statistic `List(USER_DATA)`
    ///
    /// Statistic List
    ///
    /// Weight: 5
    ///
    /// # Arguments
    ///
    /// - `params`: [`StatisticListParams`]
    ///   The parameters for this operation.
    ///
    /// # Returns
    ///
    /// [`RestApiResponse<models::StatisticListResponse>`] on success.
    ///
    /// # Errors
    ///
    /// This function will return an [`anyhow::Error`] if:
    /// - the HTTP request fails
    /// - any parameter is invalid
    /// - the response cannot be parsed
    /// - or one of the following occurs:
    ///   - `RequiredError`
    ///   - `ConnectorClientError`
    ///   - `UnauthorizedError`
    ///   - `ForbiddenError`
    ///   - `TooManyRequestsError`
    ///   - `RateLimitBanError`
    ///   - `ServerError`
    ///   - `NotFoundError`
    ///   - `NetworkError`
    ///   - `BadRequestError`
    ///
    ///
    /// For full API details, see the [Binance API Documentation](https://developers.binance.com/docs/mining/rest-api/Statistic-List).
    ///
    pub async fn statistic_list(
        &self,
        params: StatisticListParams,
    ) -> anyhow::Result<RestApiResponse<models::StatisticListResponse>> {
        self.mining_api_client.statistic_list(params).await
    }
}
