import { fetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper'; import type { Service, ConnectionTestRequest, ConnectionTestResponse, CollectionsResponse, DiscoverResponse } from '@/models/service'; const BASE_PATH = '/m/provider_jmapc'; export const serviceService = { /** * List all JMAP services for current user */ async list(capability?: string): Promise<{ services: Service[] }> { const params = capability ? `?capability=${encodeURIComponent(capability)}` : ''; return fetchWrapper.get(`${BASE_PATH}/services${params}`); }, /** * Get a single service by ID */ async fetch(id: string): Promise { return fetchWrapper.get(`${BASE_PATH}/services/${id}`); }, /** * Create a new service */ async create(service: Partial): Promise { return fetchWrapper.post(`${BASE_PATH}/services`, service); }, /** * Update an existing service */ async update(id: string, service: Partial): Promise { return fetchWrapper.put(`${BASE_PATH}/services/${id}`, service); }, /** * Delete a service */ async destroy(id: string): Promise<{ success: boolean }> { return fetchWrapper.delete(`${BASE_PATH}/services/${id}`); }, /** * Test JMAP connection */ async test(request: ConnectionTestRequest): Promise { return fetchWrapper.post(`${BASE_PATH}/services/test`, request); }, /** * Auto-discover JMAP endpoint from hostname */ async discover(hostname: string, protocol?: string, port?: number, path?: string): Promise { return fetchWrapper.post(`${BASE_PATH}/services/discover`, { hostname, protocol, port, path }); }, /** * Fetch collections for a service */ async fetchCollections(id: string): Promise { return fetchWrapper.get(`${BASE_PATH}/services/${id}/collections`); }, /** * Refresh collections for a service (re-query remote server) */ async refreshCollections(id: string): Promise { return fetchWrapper.post(`${BASE_PATH}/services/${id}/collections/refresh`, {}); }, };