import axios from 'axios'; import type { UserMessage, Message } from '../../share/types.ts'; const API_BASE_URL = '/api'; interface MessagesResponse { data: UserMessage[]; pagination: { total: number; current: number; pageSize: number; totalPages: number; }; } interface MessageResponse { data: Message; message?: string; } interface MessageCountResponse { count: number; } export const MessageAPI = { getMessages: async (params?: { page?: number, pageSize?: number, type?: string, status?: string, search?: string }): Promise => { try { const response = await axios.get(`${API_BASE_URL}/messages`, { params }); return response.data; } catch (error) { throw error; } }, sendMessage: async (data: { title: string, content: string, type: string, receiver_ids: number[] }): Promise => { try { const response = await axios.post(`${API_BASE_URL}/messages`, data); return response.data; } catch (error) { throw error; } }, getUnreadCount: async (): Promise => { try { const response = await axios.get(`${API_BASE_URL}/messages/count/unread`); return response.data; } catch (error) { throw error; } }, markAsRead: async (id: number): Promise => { try { const response = await axios.post(`${API_BASE_URL}/messages/${id}/read`); return response.data; } catch (error) { throw error; } }, deleteMessage: async (id: number): Promise => { try { const response = await axios.delete(`${API_BASE_URL}/messages/${id}`); return response.data; } catch (error) { throw error; } } };