export default {
  namespaced: true,
  state: {
    Kuser: 'admin',
    Kpassword: 'MKcloud123',
    Authentation: '',
    access_token: '',
    refresh_token: '',
    expires: new Date().getTime()
  },
  mutations: {
    setAccessToken (state, param) {
      state.access_token = param
    },
    setRefreshToken (state, param) {
      state.refresh_token = param
    },
    removeAccessToken (state) {
      state.access_token = ''
    },
    removeAuthentation (state) {
      state.Authentation = ''
    },
    updateAuthentation (state, Authentation) {
      state.Authentation = 'Bearer ' + Authentation
    },
    updateExpires (state, expires) {
      state.expires = new Date().getTime() + Number(expires) * 1000
    },
    updateRefreshToken (state, refreshToken) {
      state.refreshToken = refreshToken
    }

  },
  actions: {
    setAuthentation (context, param) {
      context.commit('updateAuthentation', param)
    },
    setExpires (context, param) {
      context.commit('updateExpires', param)
    },
    setRefreshToken (context, param) {
      context.commit('updateRefreshToken', param)
    },
    removeAuthentation (context) {
      context.commit('removeAuthentation')
    },
    removeRefreshToken (context) {
      context.commit('removeRefreshToken')
    }
  },
  getters: {
    getAccessToken (state) {
      return state.access_token
    },
    getRefreshToken (state) {
      return state.refresh_token
    }
  }

}
