/*
 * Prediction Trading REST API
 *
 * Place and manage prediction market orders, query positions, and transfer funds via the Prediction Trading 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 async_trait::async_trait;
use derive_builder::Builder;
use reqwest;
use rust_decimal::prelude::*;
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use std::collections::BTreeMap;

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

const HAS_TIME_UNIT: bool = false;

#[async_trait]
pub trait WalletApi: Send + Sync {
    async fn get_portfolio(
        &self,
        params: GetPortfolioParams,
    ) -> anyhow::Result<RestApiResponse<models::GetPortfolioResponse>>;
    async fn get_quota_status(
        &self,
        params: GetQuotaStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::GetQuotaStatusResponse>>;
    async fn list_prediction_wallets(
        &self,
        params: ListPredictionWalletsParams,
    ) -> anyhow::Result<RestApiResponse<models::ListPredictionWalletsResponse>>;
    async fn query_payment_option_balances(
        &self,
        params: QueryPaymentOptionBalancesParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryPaymentOptionBalancesResponse>>;
}

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

impl WalletApiClient {
    pub fn new(configuration: ConfigurationRestApi) -> Self {
        Self { configuration }
    }
}

/// Request parameters for the [`get_portfolio`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`get_portfolio`](#method.get_portfolio).
#[derive(Clone, Debug, Builder)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct GetPortfolioParams {
    /// User's prediction wallet address
    ///
    /// This field is **required.
    #[builder(setter(into))]
    pub wallet_address: String,
    /// Filter by prediction token ID
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub token_id: Option<String>,
    /// Filter by market ID. Must be > 0
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub market_id: Option<i64>,
    /// Filter by market topic ID. Must be > 0
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub market_topic_id: Option<i64>,
    /// If `true`, return only active (unresolved) positions
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub active_only: Option<bool>,
    /// Request validity window in milliseconds
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub recv_window: Option<i64>,
}

impl GetPortfolioParams {
    /// Create a builder for [`get_portfolio`].
    ///
    /// Required parameters:
    ///
    /// * `wallet_address` — User's prediction wallet address
    ///
    #[must_use]
    pub fn builder(wallet_address: String) -> GetPortfolioParamsBuilder {
        GetPortfolioParamsBuilder::default().wallet_address(wallet_address)
    }
}
/// Request parameters for the [`get_quota_status`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`get_quota_status`](#method.get_quota_status).
#[derive(Clone, Debug, Builder, Default)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct GetQuotaStatusParams {
    /// Request validity window in milliseconds
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub recv_window: Option<i64>,
}

impl GetQuotaStatusParams {
    /// Create a builder for [`get_quota_status`].
    ///
    #[must_use]
    pub fn builder() -> GetQuotaStatusParamsBuilder {
        GetQuotaStatusParamsBuilder::default()
    }
}
/// Request parameters for the [`list_prediction_wallets`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`list_prediction_wallets`](#method.list_prediction_wallets).
#[derive(Clone, Debug, Builder, Default)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct ListPredictionWalletsParams {
    /// Request validity window in milliseconds
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub recv_window: Option<i64>,
}

impl ListPredictionWalletsParams {
    /// Create a builder for [`list_prediction_wallets`].
    ///
    #[must_use]
    pub fn builder() -> ListPredictionWalletsParamsBuilder {
        ListPredictionWalletsParamsBuilder::default()
    }
}
/// Request parameters for the [`query_payment_option_balances`] operation.
///
/// This struct holds all of the inputs you can pass when calling
/// [`query_payment_option_balances`](#method.query_payment_option_balances).
#[derive(Clone, Debug, Builder, Default)]
#[builder(pattern = "owned", build_fn(error = "ParamBuildError"))]
pub struct QueryPaymentOptionBalancesParams {
    /// Request validity window in milliseconds
    ///
    /// This field is **optional.
    #[builder(setter(into), default)]
    pub recv_window: Option<i64>,
}

impl QueryPaymentOptionBalancesParams {
    /// Create a builder for [`query_payment_option_balances`].
    ///
    #[must_use]
    pub fn builder() -> QueryPaymentOptionBalancesParamsBuilder {
        QueryPaymentOptionBalancesParamsBuilder::default()
    }
}

#[async_trait]
impl WalletApi for WalletApiClient {
    async fn get_portfolio(
        &self,
        params: GetPortfolioParams,
    ) -> anyhow::Result<RestApiResponse<models::GetPortfolioResponse>> {
        let GetPortfolioParams {
            wallet_address,
            token_id,
            market_id,
            market_topic_id,
            active_only,
            recv_window,
        } = params;

        let mut query_params = BTreeMap::new();
        let body_params = BTreeMap::new();

        query_params.insert("walletAddress".to_string(), json!(wallet_address));

        if let Some(rw) = token_id {
            query_params.insert("tokenId".to_string(), json!(rw));
        }

        if let Some(rw) = market_id {
            query_params.insert("marketId".to_string(), json!(rw));
        }

        if let Some(rw) = market_topic_id {
            query_params.insert("marketTopicId".to_string(), json!(rw));
        }

        if let Some(rw) = active_only {
            query_params.insert("activeOnly".to_string(), json!(rw));
        }

        if let Some(rw) = recv_window {
            query_params.insert("recvWindow".to_string(), json!(rw));
        }

        send_request::<models::GetPortfolioResponse>(
            &self.configuration,
            "/sapi/v1/w3w/wallet/prediction/pnl/portfolio",
            reqwest::Method::GET,
            query_params,
            body_params,
            if HAS_TIME_UNIT {
                self.configuration.time_unit
            } else {
                None
            },
            true,
        )
        .await
    }

    async fn get_quota_status(
        &self,
        params: GetQuotaStatusParams,
    ) -> anyhow::Result<RestApiResponse<models::GetQuotaStatusResponse>> {
        let GetQuotaStatusParams { recv_window } = params;

        let mut query_params = BTreeMap::new();
        let body_params = BTreeMap::new();

        if let Some(rw) = recv_window {
            query_params.insert("recvWindow".to_string(), json!(rw));
        }

        send_request::<models::GetQuotaStatusResponse>(
            &self.configuration,
            "/sapi/v1/w3w/wallet/prediction/quota/limit/status",
            reqwest::Method::GET,
            query_params,
            body_params,
            if HAS_TIME_UNIT {
                self.configuration.time_unit
            } else {
                None
            },
            true,
        )
        .await
    }

    async fn list_prediction_wallets(
        &self,
        params: ListPredictionWalletsParams,
    ) -> anyhow::Result<RestApiResponse<models::ListPredictionWalletsResponse>> {
        let ListPredictionWalletsParams { recv_window } = params;

        let mut query_params = BTreeMap::new();
        let body_params = BTreeMap::new();

        if let Some(rw) = recv_window {
            query_params.insert("recvWindow".to_string(), json!(rw));
        }

        send_request::<models::ListPredictionWalletsResponse>(
            &self.configuration,
            "/sapi/v1/w3w/wallet/prediction/wallet/list",
            reqwest::Method::GET,
            query_params,
            body_params,
            if HAS_TIME_UNIT {
                self.configuration.time_unit
            } else {
                None
            },
            true,
        )
        .await
    }

    async fn query_payment_option_balances(
        &self,
        params: QueryPaymentOptionBalancesParams,
    ) -> anyhow::Result<RestApiResponse<models::QueryPaymentOptionBalancesResponse>> {
        let QueryPaymentOptionBalancesParams { recv_window } = params;

        let mut query_params = BTreeMap::new();
        let body_params = BTreeMap::new();

        if let Some(rw) = recv_window {
            query_params.insert("recvWindow".to_string(), json!(rw));
        }

        send_request::<models::QueryPaymentOptionBalancesResponse>(
            &self.configuration,
            "/sapi/v1/w3w/wallet/prediction/balance/payment-options",
            reqwest::Method::GET,
            query_params,
            body_params,
            if HAS_TIME_UNIT {
                self.configuration.time_unit
            } else {
                None
            },
            true,
        )
        .await
    }
}

#[cfg(all(test, feature = "w3w_prediction"))]
mod tests {
    use super::*;
    use crate::TOKIO_SHARED_RT;
    use crate::{errors::ConnectorError, models::DataFuture, models::RestApiRateLimit};
    use async_trait::async_trait;
    use std::collections::HashMap;

    struct DummyRestApiResponse<T> {
        inner: Box<dyn FnOnce() -> DataFuture<Result<T, ConnectorError>> + Send + Sync>,
        status: u16,
        headers: HashMap<String, String>,
        rate_limits: Option<Vec<RestApiRateLimit>>,
    }

    impl<T> From<DummyRestApiResponse<T>> for RestApiResponse<T> {
        fn from(dummy: DummyRestApiResponse<T>) -> Self {
            Self {
                data_fn: dummy.inner,
                status: dummy.status,
                headers: dummy.headers,
                rate_limits: dummy.rate_limits,
            }
        }
    }

    struct MockWalletApiClient {
        force_error: bool,
    }

    #[async_trait]
    impl WalletApi for MockWalletApiClient {
        async fn get_portfolio(
            &self,
            _params: GetPortfolioParams,
        ) -> anyhow::Result<RestApiResponse<models::GetPortfolioResponse>> {
            if self.force_error {
                return Err(ConnectorError::ConnectorClientError {
                    msg: "ResponseError".to_string(),
                    code: None,
                }
                .into());
            }

            let resp_json: Value = serde_json::from_str(r#"{"chainId":"56","walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","activePositionsCount":3,"totalRealizedPnl":"120.50","totalUnrealizedPnl":"15.30","totalPnl":"135.80","totalCostBasis":"450.00","totalCurrentValue":"465.30","positions":[{"id":10001,"walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","marketTopicId":4229564,"marketId":5567895,"tokenId":"112233","vendor":"PREDICT_FUN","currentShares":"1923.07","avgPrice":"0.52","currentPrice":"0.55","realizedPnl":"0.00","unrealizedPnl":"0.06","totalPnl":"0.06","pnlPercentage":"6.00","isResolved":false}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let dummy_response: models::GetPortfolioResponse =
                serde_json::from_value(resp_json.clone())
                    .expect("should parse into models::GetPortfolioResponse");

            let dummy = DummyRestApiResponse {
                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
                status: 200,
                headers: HashMap::new(),
                rate_limits: None,
            };

            Ok(dummy.into())
        }

        async fn get_quota_status(
            &self,
            _params: GetQuotaStatusParams,
        ) -> anyhow::Result<RestApiResponse<models::GetQuotaStatusResponse>> {
            if self.force_error {
                return Err(ConnectorError::ConnectorClientError {
                    msg: "ResponseError".to_string(),
                    code: None,
                }
                .into());
            }

            let resp_json: Value = serde_json::from_str(
                r#"{"dailyLimit":"10000.00","remainingDailyLimit":"8500.00"}"#,
            )
            .unwrap_or_else(|_| serde_json::json!({}));
            let dummy_response: models::GetQuotaStatusResponse =
                serde_json::from_value(resp_json.clone())
                    .expect("should parse into models::GetQuotaStatusResponse");

            let dummy = DummyRestApiResponse {
                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
                status: 200,
                headers: HashMap::new(),
                rate_limits: None,
            };

            Ok(dummy.into())
        }

        async fn list_prediction_wallets(
            &self,
            _params: ListPredictionWalletsParams,
        ) -> anyhow::Result<RestApiResponse<models::ListPredictionWalletsResponse>> {
            if self.force_error {
                return Err(ConnectorError::ConnectorClientError {
                    msg: "ResponseError".to_string(),
                    code: None,
                }
                .into());
            }

            let resp_json: Value = serde_json::from_str(r#"{"wallets":[{"walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","walletId":"5b5c1ec3be4e4416a5872b21c1ca5d20","registeredTime":1748000000000}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let dummy_response: models::ListPredictionWalletsResponse =
                serde_json::from_value(resp_json.clone())
                    .expect("should parse into models::ListPredictionWalletsResponse");

            let dummy = DummyRestApiResponse {
                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
                status: 200,
                headers: HashMap::new(),
                rate_limits: None,
            };

            Ok(dummy.into())
        }

        async fn query_payment_option_balances(
            &self,
            _params: QueryPaymentOptionBalancesParams,
        ) -> anyhow::Result<RestApiResponse<models::QueryPaymentOptionBalancesResponse>> {
            if self.force_error {
                return Err(ConnectorError::ConnectorClientError {
                    msg: "ResponseError".to_string(),
                    code: None,
                }
                .into());
            }

            let resp_json: Value = serde_json::from_str(r#"{"items":[{"accountType":"SPOT","availableBalanceDisplay":"1000.00","enabled":true}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let dummy_response: models::QueryPaymentOptionBalancesResponse =
                serde_json::from_value(resp_json.clone())
                    .expect("should parse into models::QueryPaymentOptionBalancesResponse");

            let dummy = DummyRestApiResponse {
                inner: Box::new(move || Box::pin(async move { Ok(dummy_response) })),
                status: 200,
                headers: HashMap::new(),
                rate_limits: None,
            };

            Ok(dummy.into())
        }
    }

    #[test]
    fn get_portfolio_required_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = GetPortfolioParams::builder("0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),).build().unwrap();

            let resp_json: Value = serde_json::from_str(r#"{"chainId":"56","walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","activePositionsCount":3,"totalRealizedPnl":"120.50","totalUnrealizedPnl":"15.30","totalPnl":"135.80","totalCostBasis":"450.00","totalCurrentValue":"465.30","positions":[{"id":10001,"walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","marketTopicId":4229564,"marketId":5567895,"tokenId":"112233","vendor":"PREDICT_FUN","currentShares":"1923.07","avgPrice":"0.52","currentPrice":"0.55","realizedPnl":"0.00","unrealizedPnl":"0.06","totalPnl":"0.06","pnlPercentage":"6.00","isResolved":false}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let expected_response : models::GetPortfolioResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetPortfolioResponse");

            let resp = client.get_portfolio(params).await.expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn get_portfolio_optional_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = GetPortfolioParams::builder("0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),).token_id("112233".to_string()).market_id(5567895).market_topic_id(4229564).active_only(false).recv_window(5000).build().unwrap();

            let resp_json: Value = serde_json::from_str(r#"{"chainId":"56","walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","activePositionsCount":3,"totalRealizedPnl":"120.50","totalUnrealizedPnl":"15.30","totalPnl":"135.80","totalCostBasis":"450.00","totalCurrentValue":"465.30","positions":[{"id":10001,"walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","marketTopicId":4229564,"marketId":5567895,"tokenId":"112233","vendor":"PREDICT_FUN","currentShares":"1923.07","avgPrice":"0.52","currentPrice":"0.55","realizedPnl":"0.00","unrealizedPnl":"0.06","totalPnl":"0.06","pnlPercentage":"6.00","isResolved":false}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let expected_response : models::GetPortfolioResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::GetPortfolioResponse");

            let resp = client.get_portfolio(params).await.expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn get_portfolio_response_error() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: true };

            let params = GetPortfolioParams::builder(
                "0x12e32db8817e292508c34111cbc4b23340df542c".to_string(),
            )
            .build()
            .unwrap();

            match client.get_portfolio(params).await {
                Ok(_) => panic!("Expected an error"),
                Err(err) => {
                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
                }
            }
        });
    }

    #[test]
    fn get_quota_status_required_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = GetQuotaStatusParams::builder().build().unwrap();

            let resp_json: Value = serde_json::from_str(
                r#"{"dailyLimit":"10000.00","remainingDailyLimit":"8500.00"}"#,
            )
            .unwrap_or_else(|_| serde_json::json!({}));
            let expected_response: models::GetQuotaStatusResponse =
                serde_json::from_value(resp_json.clone())
                    .expect("should parse into models::GetQuotaStatusResponse");

            let resp = client
                .get_quota_status(params)
                .await
                .expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn get_quota_status_optional_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = GetQuotaStatusParams::builder()
                .recv_window(5000)
                .build()
                .unwrap();

            let resp_json: Value = serde_json::from_str(
                r#"{"dailyLimit":"10000.00","remainingDailyLimit":"8500.00"}"#,
            )
            .unwrap_or_else(|_| serde_json::json!({}));
            let expected_response: models::GetQuotaStatusResponse =
                serde_json::from_value(resp_json.clone())
                    .expect("should parse into models::GetQuotaStatusResponse");

            let resp = client
                .get_quota_status(params)
                .await
                .expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn get_quota_status_response_error() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: true };

            let params = GetQuotaStatusParams::builder().build().unwrap();

            match client.get_quota_status(params).await {
                Ok(_) => panic!("Expected an error"),
                Err(err) => {
                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
                }
            }
        });
    }

    #[test]
    fn list_prediction_wallets_required_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = ListPredictionWalletsParams::builder().build().unwrap();

            let resp_json: Value = serde_json::from_str(r#"{"wallets":[{"walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","walletId":"5b5c1ec3be4e4416a5872b21c1ca5d20","registeredTime":1748000000000}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let expected_response : models::ListPredictionWalletsResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::ListPredictionWalletsResponse");

            let resp = client.list_prediction_wallets(params).await.expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn list_prediction_wallets_optional_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = ListPredictionWalletsParams::builder().recv_window(5000).build().unwrap();

            let resp_json: Value = serde_json::from_str(r#"{"wallets":[{"walletAddress":"0x12e32db8817e292508c34111cbc4b23340df542c","walletId":"5b5c1ec3be4e4416a5872b21c1ca5d20","registeredTime":1748000000000}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let expected_response : models::ListPredictionWalletsResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::ListPredictionWalletsResponse");

            let resp = client.list_prediction_wallets(params).await.expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn list_prediction_wallets_response_error() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: true };

            let params = ListPredictionWalletsParams::builder().build().unwrap();

            match client.list_prediction_wallets(params).await {
                Ok(_) => panic!("Expected an error"),
                Err(err) => {
                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
                }
            }
        });
    }

    #[test]
    fn query_payment_option_balances_required_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = QueryPaymentOptionBalancesParams::builder().build().unwrap();

            let resp_json: Value = serde_json::from_str(r#"{"items":[{"accountType":"SPOT","availableBalanceDisplay":"1000.00","enabled":true}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let expected_response : models::QueryPaymentOptionBalancesResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryPaymentOptionBalancesResponse");

            let resp = client.query_payment_option_balances(params).await.expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn query_payment_option_balances_optional_params_success() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: false };

            let params = QueryPaymentOptionBalancesParams::builder().recv_window(5000).build().unwrap();

            let resp_json: Value = serde_json::from_str(r#"{"items":[{"accountType":"SPOT","availableBalanceDisplay":"1000.00","enabled":true}]}"#).unwrap_or_else(|_| serde_json::json!({}));
            let expected_response : models::QueryPaymentOptionBalancesResponse = serde_json::from_value(resp_json.clone()).expect("should parse into models::QueryPaymentOptionBalancesResponse");

            let resp = client.query_payment_option_balances(params).await.expect("Expected a response");
            let data_future = resp.data();
            let actual_response = data_future.await.unwrap();
            assert_eq!(actual_response, expected_response);
        });
    }

    #[test]
    fn query_payment_option_balances_response_error() {
        TOKIO_SHARED_RT.block_on(async {
            let client = MockWalletApiClient { force_error: true };

            let params = QueryPaymentOptionBalancesParams::builder().build().unwrap();

            match client.query_payment_option_balances(params).await {
                Ok(_) => panic!("Expected an error"),
                Err(err) => {
                    assert_eq!(err.to_string(), "Connector client error: ResponseError");
                }
            }
        });
    }
}
