use crate::runtime::{self, Error};
pub struct QueryManager {
session: std::sync::Arc<runtime::Client>,
}
impl QueryManager {
pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
Self { session }
}
pub async fn query(
&self,
body: crate::models::schemas::QueryRequestBody,
) -> Result<crate::models::schemas::QueryResults, Error> {
let mut url = self.session.base_url("api");
url.push_str("/query");
let mut req = self.session.new_request("POST", &url);
req = runtime::with_header(req, "box-version", "2026.0");
let payload = serde_json::to_vec(&body)?;
req = runtime::with_json_body(req, &payload);
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
pub async fn query_insights(
&self,
body: crate::models::schemas::QueryInsightsRequestBody,
) -> Result<crate::models::schemas::QueryInsights, Error> {
let mut url = self.session.base_url("api");
url.push_str("/query_insights");
let mut req = self.session.new_request("POST", &url);
req = runtime::with_header(req, "box-version", "2026.0");
let payload = serde_json::to_vec(&body)?;
req = runtime::with_json_body(req, &payload);
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
}