import { http } from './client' import type { ChannelConnection, ChannelSyncLog, ChannelType } from '@/types' /** GET /api/channels */ export function getChannels() { return http.get('/api/channels') } /** POST /api/channels/connect */ export function connectChannel(payload: { type: ChannelType account: string syncRange?: string defaultOwnerId?: string autoReply?: boolean }) { return http.post('/api/channels/connect', payload) } export function startTelegramLogin(phone: string) { return http.post('/api/channels/telegram/start', { phone }) } export function submitTelegramCode(channelId: string, code: string) { return http.post<{ status: string; channel: ChannelConnection }>(`/api/channels/telegram/${channelId}/code`, { code }) } export function submitTelegramPassword(channelId: string, password: string) { return http.post<{ status: string; channel: ChannelConnection }>(`/api/channels/telegram/${channelId}/password`, { password }) } export function syncTelegramChannel(channelId: string) { return http.post<{ chats: number; messages: number }>(`/api/channels/${channelId}/sync`) } /** POST /api/channels/test */ export function testChannel(id: string) { return http.post<{ success: boolean; latencyMs: number; message: string }>('/api/channels/test', { id }) } /** PATCH /api/channels/:id */ export function updateChannel(id: string, payload: Partial) { return http.patch(`/api/channels/${id}`, payload) } /** DELETE /api/channels/:id */ export function deleteChannel(id: string) { return http.del<{ success: boolean }>(`/api/channels/${id}`) } /** GET /api/channels/:id/logs */ export function getChannelLogs(id: string) { return http.get(`/api/channels/${id}/logs`) }