import axios from 'axios';

export default {
  namespaced: true,
  state: {
    classes: [],
    properties: [],
  },
  mutations: {
    setClasses(state, list) {
      state.classes = list;
    },
    setProperties(state, list) {
      state.properties = list;
    },
    clearAll(state) {
      state.classes = [];
      state.properties = [];
    },
  },
  getters: {},
  actions: {
    async init({
      dispatch,
    }) {
      await dispatch('clearAll');
      dispatch('getClasses');
    },
    getClasses({
      commit,
    }) {
      axios
        .get('api/info/getAllClasses')
        .then(result => commit('setClasses', result.data))
        .catch(ex => console.log(ex.response));
    },
    getProperties({
      commit,
    }, obj) {
      axios
        .get(`api/info/${obj.fullName}`)
        .then(result => commit('setProperties', result.data))
        .catch(ex => console.log(ex.response));
    },
    clearAll({commit}){
     console.log("it was here");
      commit('clearAll')
    }
  },
};
