use super::types::{
BookConsultationRequest, BookConsultationResult, CaseLead, CaseLeadIdResult, CaseMatter,
LawyerCredentialMyView, LawyerSummary, LegalConsultation, LegalServiceOrder, LegalServiceSku,
ListLawyersParams, SubmitCaseLeadRequest,
};
use crate::billing::entitlements::urlencoding;
use crate::core::client::Client;
use crate::shared::{Error, Result};
use tokio_util::sync::CancellationToken;
impl Client {
pub async fn list_lawyers(
&self,
params: Option<&ListLawyersParams>,
signal: Option<CancellationToken>,
) -> Result<Vec<LawyerSummary>> {
let mut qs: Vec<String> = Vec::new();
if let Some(p) = params {
if let Some(pa) = &p.practice_area {
qs.push(format!("practiceArea={}", urlencoding(pa)));
}
if let Some(loc) = &p.location {
qs.push(format!("location={}", urlencoding(loc)));
}
if let Some(n) = p.page_no {
qs.push(format!("pageNo={n}"));
}
if let Some(sz) = p.page_size {
qs.push(format!("pageSize={sz}"));
}
}
let path = if qs.is_empty() {
"/casehall/app/lawyers".to_string()
} else {
format!("/casehall/app/lawyers?{}", qs.join("&"))
};
self.commerce_get_list(&path, signal).await
}
pub async fn get_lawyer(
&self,
id: i64,
signal: Option<CancellationToken>,
) -> Result<LawyerSummary> {
self.commerce_get_opt::<LawyerSummary>(&format!("/casehall/app/lawyers/{id}"), signal)
.await?
.ok_or_else(|| Error::other(format!("lawyer {id} not found")))
}
pub async fn submit_case_lead(
&self,
req: &SubmitCaseLeadRequest,
signal: Option<CancellationToken>,
) -> Result<CaseLeadIdResult> {
let body = serde_json::to_string(req)
.map_err(|e| Error::other(format!("submitCaseLead: marshal: {e}")))?;
Ok(self
.commerce_post_opt::<CaseLeadIdResult>("/casehall/me/case-leads", Some(&body), signal)
.await?
.unwrap_or(CaseLeadIdResult { id: 0 }))
}
pub async fn list_my_case_leads(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<CaseLead>> {
self.commerce_get_list("/casehall/me/case-leads", signal)
.await
}
pub async fn get_my_cases(&self, signal: Option<CancellationToken>) -> Result<Vec<CaseMatter>> {
self.commerce_get_list("/casehall/me/cases", signal).await
}
pub async fn book_consultation(
&self,
req: &BookConsultationRequest,
signal: Option<CancellationToken>,
) -> Result<BookConsultationResult> {
let body = serde_json::to_string(req)
.map_err(|e| Error::other(format!("bookConsultation: marshal: {e}")))?;
Ok(self
.commerce_post_opt::<BookConsultationResult>(
"/casehall/me/consultations",
Some(&body),
signal,
)
.await?
.unwrap_or(BookConsultationResult { consultation_id: 0 }))
}
pub async fn list_my_consultations(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<LegalConsultation>> {
self.commerce_get_list("/casehall/me/consultations", signal)
.await
}
pub async fn list_my_legal_orders(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<LegalServiceOrder>> {
self.commerce_get_list("/casehall/me/orders", signal).await
}
pub async fn list_legal_skus(
&self,
region: Option<&str>,
signal: Option<CancellationToken>,
) -> Result<Vec<LegalServiceSku>> {
let path = match region {
Some(r) => format!(
"/casehall/app/legal-skus?region={}&benefitType=LEGAL_SERVICE",
urlencoding(r)
),
None => "/casehall/app/legal-skus?benefitType=LEGAL_SERVICE".to_string(),
};
self.commerce_get_list(&path, signal).await
}
pub async fn get_my_lawyer_credential_status(
&self,
signal: Option<CancellationToken>,
) -> Result<Vec<LawyerCredentialMyView>> {
self.commerce_get_list("/api/casehall/lawyer-credentials/my", signal)
.await
}
}