import {request} from '/@/utils/service';
import {PageQuery, AddReq, DelReq, EditReq, InfoReq} from '@fast-crud/fast-crud';

export const apiPrefix = '/api/system/message_center/';

export function GetList(query: PageQuery) {
    return request({
        url: apiPrefix,
        method: 'get',
        params: query,
    });
}

export function GetObj(id: InfoReq) {
    return request({
        url: apiPrefix + id + '/',
        method: 'get',
    });
}

/**
 * 获取自己接收的消息
 * @param query
 * @returns {*}
 * @constructor
 */
export function GetSelfReceive (query:PageQuery) {
    return request({
        url: apiPrefix + 'get_self_receive/',
        method: 'get',
        params: query
    })
}

export function AddObj(obj: AddReq) {
    return request({
        url: apiPrefix,
        method: 'post',
        data: obj,
    });
}




export function UpdateObj(obj: EditReq) {
    return request({
        url: apiPrefix + obj.id + '/',
        method: 'put',
        data: obj,
    });
}

export function DelObj(id: DelReq) {
    return request({
        url: apiPrefix + id + '/',
        method: 'delete',
        data: {id},
    });
}

/**
 * 批量标记消息为已读
 * @param messageIds 消息ID数组
 * @returns {*}
 */
export function MarkMessagesRead(messageIds: number[]) {
    return request({
        url: apiPrefix + 'mark_app_user_message_read/',
        method: 'post',
        data: {
            message_ids: messageIds
        },
    });
}

/* 消息关联  /api/system/message_center/create_message_association/ */

/* export function createMessageAssociation(messageIds: number[]) {
    return request({
        url: '/api/system/message_center/create_message_association/',
        method: 'post',
        data: {
            message_ids: messageIds,
            is_read:false
        },
    });
} */