const messages = {
  state() {
    return {
      messages: [],
      announcements: [],
    };
  },

  mutations: {
    set_messages(state, data) {
      state.messages = data;
    },
    set_announcements(state, data) {
      state.announcements = data;
    }
  },

  actions: {
    async fetchMessages({commit, state}, that) {
      commit("set_messages", (await that.$apis.getUnreadAnnouncements()).data.data);
      commit("set_announcements", (await that.$apis.getUnreadMessages()).data.data);
    }
  },

  getters: {
    unReadMessages(state) {
      return state.messages;
    },
    unReadAnnouncements(state) {
      return state.announcements;
    },
  },
};

export default messages;