import {axios} from "@/requests/axios.config";

const prefix = "/communication";

function getAllCommunications(payload) {
    const {page, size, sort} = payload;
     return axios.get(`${prefix}`, {params: {page, size, sort}});

}

function getCommunicationStarers(communicationId) {
    return axios.get(`${prefix}/${communicationId}/stars/users`);
}

function getCommunicationDetail(communicationId) {
    return axios.get(`${prefix}/${communicationId}`);

}

function getUserPublishCommunication(payload){
    const {userId, page, size, sort} = payload;
    return axios.get(`${prefix}/users/${userId}`,{params:{page, size, sort}});
}

function starCommunication(userId,communicationId){
    return axios.post(`${prefix}/${communicationId}/stars?userId=${userId}`);
}

function cancelStarCommunication(userId,communicationId){
    return axios.delete(`${prefix}/${communicationId}/stars`,{params:{userId}});
}

function getStarredCommunication(payload){
    const {userId, page, size, sort} = payload;
    return axios.get(`${prefix}/stars/users/${userId}`,{params:{page, size, sort}});
}

function uploadFile(file){
    let data = new FormData();
    data.append("file", file);
    return axios.post(`${prefix}/upload`, data);
}

function postCommunication(communication){
    return axios.post(`${prefix}`,communication);
}

const communicationAPIs = {
    getAllCommunications,
    getCommunicationStarers,
    getCommunicationDetail,
    getUserPublishCommunication,
    starCommunication,
    cancelStarCommunication,
    getStarredCommunication,
    uploadFile,
    postCommunication,
};

export default communicationAPIs;