// ВАЖНО: пути и поля — предположение. Подставьте реальные эндпоинты бэкенда. import api from '@/api/client' export type ReportType = 'call' | 'sms' | 'chat' export type Channel = 'telegram' | 'whatsapp' | 'max' export interface ReportRow { id: string type: ReportType channel?: Channel | null // только для type = 'chat' started_at: string // ISO; дата и время из таблицы одним полем direction: 'in' | 'out' phone: string contact_name?: string | null company?: string | null value: number // звонок — секунды, SMS/чат — число сообщений answered: boolean recording_url?: string | null // звонок last_message?: string | null // SMS / чат manager: string manager_id?: number | null notes_count?: number // число заметок, для индикатора в таблице status: string // «Отвечен», «Пропущен, перезвон не совершен», … } export interface ReportParams { offset?: number; limit?: number type?: ReportType; manager?: string; direction?: 'in' | 'out' status?: string; content?: string; date_from?: string; date_to?: string } export interface ChatSummary { id: string contact_name?: string | null phone: string last_message?: string | null last_at?: string | null messages_count: number } export interface Note { id: number text: string author: string created_at: string can_delete: boolean // права решает сервер: автор или суперадмин } export interface ChatMessage { id: string; direction: 'in' | 'out'; text: string; at: string; author?: string } export const telephonyApi = { list: (params: ReportParams) => api.get<{ data: ReportRow[]; total_count: number }>('/telephony/report', { params }).then((r) => r.data), // Заметки общие: видны всем, у кого есть доступ к разделу. id — id строки отчёта notes: (id: string) => api.get<{ data: Note[] }>(`/telephony/report/${id}/notes`).then((r) => r.data.data), addNote: (id: string, text: string) => api.post(`/telephony/report/${id}/notes`, { text }), deleteNote: (id: string, noteId: number) => api.delete(`/telephony/report/${id}/notes/${noteId}`), // Диалоги менеджера в одном канале chats: (p: { channel: Channel; manager_id: string | number; search?: string; limit?: number }) => api.get<{ data: ChatSummary[]; total_count: number }>('/telephony/chats', { params: p }).then((r) => r.data), // Переписка постранично: before — id самого раннего из уже загруженных сообщений thread: (chatId: string, p: { before?: string; limit?: number }) => api.get<{ data: ChatMessage[]; has_more: boolean }>(`/telephony/chats/${chatId}/messages`, { params: p }).then((r) => r.data), download: (params: ReportParams) => api.get('/telephony/report/xlsx', { params, responseType: 'blob' }).then((r) => r.data as BlobPart), }