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

const prefix = "/message";

function getUnreadMessages(period) {
  if (period === undefined) {
    return axios.get(`${prefix}/getUnread`);
  } else {
    return axios.get(`${prefix}/getUnread`, {params: {day: period}});
  }
}

function createMessage(data) {
  return axios.post(`${prefix}`, data);
}

function updateMessage(data) {
  return axios.put(`${prefix}`, data);
}

function deleteMessage(id) {
  return axios.delete(`${prefix}`, {params: {id}});
}

function getCommentsByCourseId(courseId) {
  return axios.get(`${prefix}/getByCourseId`, {params: {courseId}});
}

function getViewByMessage(id) {
  return axios.get(`${prefix}/getView`, {params: {id}});
}

function readMessage(id) {
  return axios.put(`${prefix}/read`, {id});
}

const messageAPIs = {
  getUnreadMessages,
  createMessage,
  updateMessage,
  getCommentsByCourseId,
  deleteMessage,
  getViewByMessage,
  readMessage,
};

export default messageAPIs;