import { $get, $body } from '/@/utils/request';

/**
 * 消息通知相关接口
 */
export const MessageApi = {
    /**
     * 发送消息
     */
    sendMessage(data: {
        title: string;
        content: string;
        type: number;
        receiverId: number;
        priority?: number;
        bizType?: string;
        bizId?: number;
    }) {
        return $body('/message/send', data);
    },

    /**
     * 批量发送消息
     */
    batchSendMessage(data: {
        title: string;
        content: string;
        type: number;
        receiverIds: number[];
        priority?: number;
    }) {
        return $body('/message/batchSend', data);
    },

    /**
     * 分页查询消息列表
     */
    getMessageList(params: {
        pageNum?: number;
        pageSize?: number;
        type?: number;
        status?: number;
        title?: string;
    }) {
        return $get('/message/list', params);
    },

    /**
     * 获取消息详情
     */
    getMessageDetail(messageId: number) {
        return $get(`/message/detail/${messageId}`);
    },

    /**
     * 标记消息已读
     */
    markAsRead(messageId: number) {
        return $body(`/message/read/${messageId}`, {});
    },

    /**
     * 批量标记已读
     */
    batchMarkAsRead(ids: number[]) {
        return $body('/message/batchRead', { ids });
    },

    /**
     * 全部标记已读
     */
    markAllAsRead(type?: number) {
        return $body('/message/readAll' + (type ? `?type=${type}` : ''), {});
    },

    /**
     * 删除消息
     */
    deleteMessage(messageId: number) {
        return $body(`/message/delete/${messageId}`, {});
    },

    /**
     * 批量删除消息
     */
    batchDeleteMessage(ids: number[]) {
        return $body('/message/batchDelete', { ids });
    },

    /**
     * 获取未读消息数量
     */
    getUnreadCount() {
        return $get('/message/unreadCount');
    },

    /**
     * 按类型获取未读消息数量
     */
    getUnreadCountByType() {
        return $get('/message/unreadCountByType');
    },

    /**
     * 获取最新未读消息
     */
    getLatestUnread(limit: number = 5) {
        return $get('/message/latestUnread', { limit });
    }
};

// Mock 数据支持（当后端不可用时）
export const MessageMockData = {
    list: [
        {
            id: 1,
            title: '系统升级通知',
            content: '系统将于2024年1月20日凌晨2:00-4:00进行升级维护，届时系统将暂停服务，请提前做好准备。',
            type: 1,
            senderId: 0,
            senderName: '系统',
            receiverId: 1,
            receiverName: '管理员',
            status: 0,
            priority: 2,
            createTime: '2024-01-15 10:00:00'
        },
        {
            id: 2,
            title: '新功能上线',
            content: '消息通知中心功能已上线，您可以在此查看所有消息通知。',
            type: 1,
            senderId: 0,
            senderName: '系统',
            receiverId: 1,
            receiverName: '管理员',
            status: 0,
            priority: 0,
            createTime: '2024-01-15 09:30:00'
        },
        {
            id: 3,
            title: '待办事项提醒',
            content: '您有3个待审批的工单，请及时处理。',
            type: 3,
            senderId: 0,
            senderName: '系统',
            receiverId: 1,
            receiverName: '管理员',
            status: 0,
            priority: 1,
            createTime: '2024-01-15 09:00:00'
        },
        {
            id: 4,
            title: '欢迎使用',
            content: '欢迎使用洗车管理系统，如有问题请联系管理员。',
            type: 2,
            senderId: 0,
            senderName: '系统',
            receiverId: 1,
            receiverName: '管理员',
            status: 1,
            priority: 0,
            createTime: '2024-01-14 15:00:00',
            readTime: '2024-01-14 16:00:00'
        }
    ],
    unreadCount: 3,
    unreadCountByType: {
        1: 2, // 系统通知
        2: 0, // 站内信
        3: 1, // 待办事项
        4: 0  // 公告通知
    }
};
