import axios from 'axios'

export default {
  namespaced: true,
  state: {
    user: {},
    userAddress: {},
    users: []
  },
  mutations: {
    setUser(state, user) {
      state.user = user;
    },
    setAddress(state, address) {
      state.userAddress = address;
    },
    setUsers(state, users) {
      state.users = users;
    }
  },
  getters: {},
  actions: {
    getUser({
      commit
    }, id) {
      axios
        .get(`/api/user/${id}`)
        .then(result => commit("setUser", result.data));
    },
    updateUser({
      commit
    }, user) {
      axios
        .put('/api/user', user)
        .then(result => commit("setUser", result.data));
    },
    getUserAddress({
      commit
    }, userId) {
      axios
        .get(`/api/user/getuseraddress/${userId}`)
        .then(result => commit("setAddress", result.data));
    },
    getUsers({
      commit
    }) {
      axios
        .get('/api/user/GetCustomers')
        .then(result => commit("setUsers", result.data));
    }
  }
}
