Skip to main content

acosmi/casehall/
client.rs

1//! 法律案件咨询 namespace 业务方法。端口自 `casehall/client.ts`(declaration-merging → `impl Client` 块)。
2//!
3//! 端点路径形如 `/casehall/app/...`(C 端公开)/ `/casehall/me/...`(登录态)。
4//!
5//! bug-for-bug:多数方法 `@experimental`(后端 consumer 端点尚未实现,casehall 模块当前仅
6//! `getMyLawyerCredentialStatus` 在产;调用将返回 404)。SDK 仍按 TS 现状封装。
7
8use super::types::{
9    BookConsultationRequest, BookConsultationResult, CaseLead, CaseLeadIdResult, CaseMatter,
10    LawyerCredentialMyView, LawyerSummary, LegalConsultation, LegalServiceOrder, LegalServiceSku,
11    ListLawyersParams, SubmitCaseLeadRequest,
12};
13use crate::billing::entitlements::urlencoding;
14use crate::core::client::Client;
15use crate::shared::{Error, Result};
16use tokio_util::sync::CancellationToken;
17
18impl Client {
19    // ===========================================================================
20    // 律师库(C 端公开)
21    // ===========================================================================
22
23    /// 列出已认证律师(公开端点,仅 VERIFIED + ACTIVE;PII L3 字段已脱敏)。对应 TS `listLawyers`。
24    ///
25    /// **@experimental** 对应后端 consumer 端点尚未实现;调用将返回 404。空 data → []。
26    pub async fn list_lawyers(
27        &self,
28        params: Option<&ListLawyersParams>,
29        signal: Option<CancellationToken>,
30    ) -> Result<Vec<LawyerSummary>> {
31        let mut qs: Vec<String> = Vec::new();
32        if let Some(p) = params {
33            if let Some(pa) = &p.practice_area {
34                qs.push(format!("practiceArea={}", urlencoding(pa)));
35            }
36            if let Some(loc) = &p.location {
37                qs.push(format!("location={}", urlencoding(loc)));
38            }
39            if let Some(n) = p.page_no {
40                qs.push(format!("pageNo={n}"));
41            }
42            if let Some(sz) = p.page_size {
43                qs.push(format!("pageSize={sz}"));
44            }
45        }
46        let path = if qs.is_empty() {
47            "/casehall/app/lawyers".to_string()
48        } else {
49            format!("/casehall/app/lawyers?{}", qs.join("&"))
50        };
51        self.commerce_get_list(&path, signal).await
52    }
53
54    /// 获取律师公开详情(脱敏)。对应 TS `getLawyer`。
55    ///
56    /// **@experimental** 404 未实现。空 data → Err(`lawyer {id} not found`)。
57    pub async fn get_lawyer(
58        &self,
59        id: i64,
60        signal: Option<CancellationToken>,
61    ) -> Result<LawyerSummary> {
62        self.commerce_get_opt::<LawyerSummary>(&format!("/casehall/app/lawyers/{id}"), signal)
63            .await?
64            .ok_or_else(|| Error::other(format!("lawyer {id} not found")))
65    }
66
67    // ===========================================================================
68    // 案件线索(C 端登录态)
69    // ===========================================================================
70
71    /// 提交案件线索(登录态)。对应 TS `submitCaseLead`。
72    ///
73    /// **@experimental** 404 未实现。空 data → 回退 `{id:0}`(TS `?? {id:0}`)。
74    pub async fn submit_case_lead(
75        &self,
76        req: &SubmitCaseLeadRequest,
77        signal: Option<CancellationToken>,
78    ) -> Result<CaseLeadIdResult> {
79        let body = serde_json::to_string(req)
80            .map_err(|e| Error::other(format!("submitCaseLead: marshal: {e}")))?;
81        Ok(self
82            .commerce_post_opt::<CaseLeadIdResult>("/casehall/me/case-leads", Some(&body), signal)
83            .await?
84            .unwrap_or(CaseLeadIdResult { id: 0 }))
85    }
86
87    /// 我的案件线索列表。对应 TS `listMyCaseLeads`。**@experimental** 404 未实现。空 data → []。
88    pub async fn list_my_case_leads(
89        &self,
90        signal: Option<CancellationToken>,
91    ) -> Result<Vec<CaseLead>> {
92        self.commerce_get_list("/casehall/me/case-leads", signal)
93            .await
94    }
95
96    /// 我的案件列表(委托后)。对应 TS `getMyCases`。**@experimental** 404 未实现。空 data → []。
97    pub async fn get_my_cases(&self, signal: Option<CancellationToken>) -> Result<Vec<CaseMatter>> {
98        self.commerce_get_list("/casehall/me/cases", signal).await
99    }
100
101    // ===========================================================================
102    // 法律咨询
103    // ===========================================================================
104
105    /// 预约法律咨询(sku_code 必填;lawyer_id 留空走 AI 推荐池)。对应 TS `bookConsultation`。
106    ///
107    /// **@experimental** 404 未实现。空 data → 回退 `{consultationId:0}`。
108    pub async fn book_consultation(
109        &self,
110        req: &BookConsultationRequest,
111        signal: Option<CancellationToken>,
112    ) -> Result<BookConsultationResult> {
113        let body = serde_json::to_string(req)
114            .map_err(|e| Error::other(format!("bookConsultation: marshal: {e}")))?;
115        Ok(self
116            .commerce_post_opt::<BookConsultationResult>(
117                "/casehall/me/consultations",
118                Some(&body),
119                signal,
120            )
121            .await?
122            .unwrap_or(BookConsultationResult { consultation_id: 0 }))
123    }
124
125    /// 我的咨询单列表。对应 TS `listMyConsultations`。**@experimental** 404 未实现。空 data → []。
126    pub async fn list_my_consultations(
127        &self,
128        signal: Option<CancellationToken>,
129    ) -> Result<Vec<LegalConsultation>> {
130        self.commerce_get_list("/casehall/me/consultations", signal)
131            .await
132    }
133
134    // ===========================================================================
135    // 法律服务订单 & SKU
136    // ===========================================================================
137
138    /// 我的法律服务订单列表。对应 TS `listMyLegalOrders`。**@experimental** 404 未实现。空 data → []。
139    pub async fn list_my_legal_orders(
140        &self,
141        signal: Option<CancellationToken>,
142    ) -> Result<Vec<LegalServiceOrder>> {
143        self.commerce_get_list("/casehall/me/orders", signal).await
144    }
145
146    /// 列出公开的 LEGAL_SERVICE SKU(匿名可调用,复用 dist_compliance_sku benefit_type='LEGAL_SERVICE')。
147    /// 对应 TS `listLegalSKUs`。
148    ///
149    /// **@experimental** 404 未实现。**强制拼 `benefitType=LEGAL_SERVICE`**(bug-for-bug)。空 data → []。
150    pub async fn list_legal_skus(
151        &self,
152        region: Option<&str>,
153        signal: Option<CancellationToken>,
154    ) -> Result<Vec<LegalServiceSku>> {
155        let path = match region {
156            Some(r) => format!(
157                "/casehall/app/legal-skus?region={}&benefitType=LEGAL_SERVICE",
158                urlencoding(r)
159            ),
160            None => "/casehall/app/legal-skus?benefitType=LEGAL_SERVICE".to_string(),
161        };
162        self.commerce_get_list(&path, signal).await
163    }
164
165    // ===========================================================================
166    // 律师自查执业证审核状态(v2.0.0+,唯一在产端点)
167    // ===========================================================================
168
169    /// 律师自查执业证审核状态 —— 返回登录用户作为律师身份提交的所有 credential 列表。
170    /// 普通用户(无 lawyer_profile)调返 [] 不抛。对应 TS `getMyLawyerCredentialStatus`。
171    ///
172    /// 端点 `GET /api/casehall/lawyer-credentials/my`(注意:TS 原样裸路径,经 doJSON 前缀 base)。
173    pub async fn get_my_lawyer_credential_status(
174        &self,
175        signal: Option<CancellationToken>,
176    ) -> Result<Vec<LawyerCredentialMyView>> {
177        // bug-for-bug:TS 此处 path 以 `/api/casehall/...` 开头(doJSON 仍前缀 base/api/v4),保持不动。
178        self.commerce_get_list("/api/casehall/lawyer-credentials/my", signal)
179            .await
180    }
181}