/*
 * Copyright (c) 2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */

import {useApi} from "~/modules/api";
import {formatRequestRecord, RequestRecord} from "~/modules/api/utils";

//---------------------------------------------------------------------------------

export async function getMessage(messageId: number) {
    const response = await useApi('auth')
        .get('/chat/messages/'+messageId);

    return response.data;
}

export async function editMessage(messageId: number, attributes: Record<string, any>) {
    const response = await useApi('auth')
        .post('/chat/messages/'+messageId, attributes);

    return response.data;
}

export async function dropMessage(messageId: number) {
    const response = await useApi('auth')
        .delete('/chat/messages/'+messageId);

    return response.data;
}

//---------------------------------------------------------------------------------

export async function getMessages(record?: RequestRecord) {
    const response = await useApi('auth')
        .get('/chat/messages' + formatRequestRecord(record));

    return response.data;
}

export async function addMessage(data: Record<string, any>) {
    const response = await useApi('auth')
        .post('/chat/messages', data);

    return response.data;
}
