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

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

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

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

export default messages;