import { get, post } from '../client' import { idempotencyKey } from '../idempotency' /** 服务预约 */ export const serviceAppointmentService = { async getCurrentServiceLocation() { try { const home: any = await get('/home') const location = home?.serviceLocation if (!location?.id) return null return { id: location.id, name: location.name || '已选服务站点' } } catch { return null } }, getMyAppointments() { return get('/service-appointments') }, getAppointmentDetail(id: string) { return get(`/service-appointments/${encodeURIComponent(id)}`) }, createAppointment(payload: Record) { return post('/service-appointments', { serviceLocationId: payload.serviceLocationId, serviceType: payload.serviceType, preferredDate: payload.preferredDate, preferredTimeSlot: payload.preferredTimeSlot, userNote: payload.userNote, }) }, cancelAppointment(id: string, reason?: string) { return post(`/service-appointments/${encodeURIComponent(id)}/cancel`, { reason: reason || '' }) }, } /** 善缘服务站 */ export const serviceStationService = { async getStation() { const home: any = await get('/home') return home?.serviceLocation || null }, async getVisibleAnnouncements(locationId: string) { if (!locationId) return [] try { const list = await get(`/service-locations/${encodeURIComponent(locationId)}/announcements`) return Array.isArray(list) ? list : [] } catch { return [] } }, } /** 专项公益服务项目 */ export const serviceProgramService = { getPrograms(params: Record = {}) { return get('/service-programs', params) }, getProgramDetail(id: string) { return get(`/service-programs/${encodeURIComponent(id)}`) }, applyToProgram(id: string) { return post(`/service-programs/${encodeURIComponent(id)}/apply`, {}, { idempotencyKey: idempotencyKey('program-apply', id) }) }, getMyApplications() { return get('/service-programs/my') }, } /** 公益内容(婚恋课堂 / 反诈) */ export const contentService = { getCategories() { return get('/content/categories') }, getArticles(params: Record = {}) { return get('/content/articles', params) }, getArticleDetail(id: string) { return get(`/content/articles/${encodeURIComponent(id)}`) }, } /** 婚恋咨询 / 婚前辅导 */ export const counselingService = { intro() { return get('/counseling/services/intro') }, apply(payload: Record) { return post('/counseling/services', payload, { idempotencyKey: idempotencyKey('counseling-apply', payload.serviceType) }) }, myServices(limit = 20) { return get('/counseling/services', { limit }) }, detail(id: string) { return get(`/counseling/services/${encodeURIComponent(id)}`) }, cancel(id: string, reason?: string) { return post(`/counseling/services/${encodeURIComponent(id)}/cancel`, { reason: reason || '' }) }, confirmCompanion(id: string) { return post(`/counseling/services/${encodeURIComponent(id)}/companion-confirm`, {}, { idempotencyKey: idempotencyKey('companion-confirm', id), }) }, }