import {createStore} from "vuex";

const users = {
  namespaced: true,
  state: {
    usersOffSite: [],
  },
  mutations: {
    setUsersOffSite(state, users) {
      state.usersOffSite = users
    }
  },
  getters: {
    usersOffSite: state => {
      return state.usersOffSite
    }
  },
  actions: {
    resetStore({state}) {
      state.notIncludedSiteUsersList = []
    },
    saveUsersOffSite({commit}, users) {
      console.log(users)
      commit('setUsersOffSite', users)
    }
  },
}

const store = createStore({
  plugins: [],
  modules: {
    users
  },
})

class ServiceOfUsers {
  constructor(adapter, store) {
    this.adapter = adapter
    this.store = store
  }

  async fetchUsersOffSite() {
    const usersList = [{id: 1, name: 'user1'}, {id: 2, name: 'user2'}]
    this.store.dispatch('users/saveUsersOffSite', usersList)
  }
}

const serviceOfUsers = new ServiceOfUsers({}, store)

export {store, serviceOfUsers}