import { get, post, put } from '../client' import { opGet, opPost } from '../operatorClient' import { idempotencyKey } from '../idempotency' /** 用户端红娘服务(申请/我的服务/详情/推荐) */ export const matchmakerService = { applyService(payload: Record) { return post('/matchmaker/services', payload, { idempotencyKey: idempotencyKey('matchmaker-apply') }) }, getMyServices(params: Record = {}) { return get('/matchmaker/services', params) }, async getServiceDetail(serviceId: string) { // 用户端后端未注册 GET /matchmaker/services/{id}(仅列表接口)—— // 由列表按 id 派生,避免对不存在路由发起 404 请求。 const result: any = await get('/matchmaker/services', { limit: 50 }) const list: any[] = result?.items || result?.records || (Array.isArray(result) ? result : []) return list.find((s: any) => (s.serviceId || s.id) === serviceId) ?? null }, confirmService(serviceId: string) { return post(`/matchmaker/services/${encodeURIComponent(serviceId)}/confirm`, {}, { idempotencyKey: idempotencyKey('matchmaker-confirm', serviceId), }) }, withdrawService(serviceId: string) { return post(`/matchmaker/services/${encodeURIComponent(serviceId)}/withdraw`, {}, { idempotencyKey: idempotencyKey('matchmaker-withdraw', serviceId), }) }, getRecommendations(params: Record = {}) { return get('/matchmaker/recommendations', params) }, markRecommendationViewed(recommendationId: string) { return put(`/matchmaker/recommendations/${encodeURIComponent(recommendationId)}/viewed`) }, acceptRecommendation(recommendationId: string) { return post(`/matchmaker/recommendations/${encodeURIComponent(recommendationId)}/accept`, {}, { idempotencyKey: idempotencyKey('mm-rec-accept', recommendationId), }) }, passRecommendation(recommendationId: string) { return post(`/matchmaker/recommendations/${encodeURIComponent(recommendationId)}/pass`, {}, { idempotencyKey: idempotencyKey('mm-rec-pass', recommendationId), }) }, } /** * 红娘工作台(Operator 会话)。 * 不变量:红娘只做推荐/跟进,**不可替用户 Like/Pass**(AGENTS 第 5 条)。 */ export const operatorMatchmakerService = { dashboard() { return opGet('/operator/matchmaker/dashboard') }, myAssignments() { return opGet('/operator/matchmaker/assignments/my') }, recommendations() { return opGet('/operator/matchmaker/recommendations') }, pending() { return opGet('/operator/matchmaker/pending') }, managementServices() { return opGet('/operator/matchmaker/management/services') }, serviceDetail(id: string) { return opGet(`/operator/matchmaker/services/${encodeURIComponent(id)}`) }, recommend(serviceId: string, payload: Record) { return opPost(`/operator/matchmaker/services/${encodeURIComponent(serviceId)}/recommend`, payload) }, followup(serviceId: string, payload: Record) { return opPost(`/operator/matchmaker/services/${encodeURIComponent(serviceId)}/followup`, payload) }, complete(serviceId: string) { return opPost(`/operator/matchmaker/services/${encodeURIComponent(serviceId)}/complete`, {}) }, myContactAuthorizations() { return opGet('/operator/matchmaker/contact-authorizations/my') }, requestContactAuthorization(payload: Record) { return opPost('/operator/matchmaker/contact-authorizations', payload) }, revokeContactAuthorization(id: string, reason: string) { return opPost(`/operator/matchmaker/contact-authorizations/${encodeURIComponent(id)}/revoke`, { reason }) }, referralHistory() { return opGet('/referrals/operator/history') }, referToServiceStation(payload: Record) { return opPost('/referrals/service-station', payload) }, referToActivity(payload: Record) { return opPost('/referrals/activity', payload) }, } /** 红娘转介(用户侧确认) */ export const referralService = { getMyReferralHistory() { return get('/referrals/my-history') }, confirmReferral(targetId: string, targetType: 'service_station' | 'activity') { return post(`/referrals/${encodeURIComponent(targetId)}/confirm`, { targetType }, { idempotencyKey: idempotencyKey('referral-confirm', `${targetId}:${targetType}`), }) }, } /** 受控联系授权(用户单独明示同意,INV) */ export const contactConsentService = { my() { return get('/contact-authorizations/my') }, consent(id: string) { return post(`/contact-authorizations/${encodeURIComponent(id)}/consent`, {}, { idempotencyKey: idempotencyKey('contact-consent', id), }) }, decline(id: string) { return post(`/contact-authorizations/${encodeURIComponent(id)}/decline`, {}, { idempotencyKey: idempotencyKey('contact-decline', id), }) }, }