/*
 * 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 {CollectionResponseType} from "@/modules/api/type";
import {AuthContact} from "@chamesu/common/domains/auth/contact";
import {ChatMember} from "@chamesu/common/domains/chat/member";
import {ChatRoom} from "@chamesu/common/domains/chat/room";
import {useApi} from "~/modules/api";
import {formatRequestRecord, RequestRecord} from "~/modules/api/utils";

export async function dropRoom(id: string) : Promise<CollectionResponseType<ChatRoom>> {
    const {data: response} = await useApi('auth')
        .delete('/chat/rooms/'+id);

    return response;
}


export async function getRoomMemberContacts(id: string, record?: RequestRecord) : Promise<CollectionResponseType<AuthContact>> {
    const {data: response} = await useApi('auth')
        .get('/chat/rooms/'+id+'/member-contacts' + formatRequestRecord(record));

    return response;
}

export async function getRoomMembers<T extends CollectionResponseType<ChatMember>>(id: string, record?: RequestRecord) : Promise<T> {
    const response = await useApi('auth')
        .get<T>('/chat/rooms/'+id+'/members' + formatRequestRecord(record));

    return response.data;
}
