use std::sync::Arc;
use reqwest::Method;
use crate::constants::ENDPOINT_ROUTING_EXPLAIN;
use crate::error::Result;
use crate::http::HttpTransport;
use crate::options::RequestOptions;
use crate::types::{RoutingExplainParams, RoutingExplainResult};
use super::require;
pub struct Routing {
t: Arc<HttpTransport>,
}
impl Routing {
pub(crate) fn new(t: Arc<HttpTransport>) -> Self {
Self { t }
}
pub async fn explain(
&self,
params: RoutingExplainParams,
req: impl Into<Option<RequestOptions>>,
) -> Result<RoutingExplainResult> {
let body =
serde_json::to_value(¶ms).map_err(|e| crate::Error::Decode(e.to_string()))?;
let (data, _) = self
.t
.request(
Method::POST,
ENDPOINT_ROUTING_EXPLAIN,
Some(&body),
&[],
req.into().as_ref(),
)
.await?;
require(data)
}
}