import { fetchSSOConfigInfo } from '@/api/portal/portal';
import { setSSOConfig } from '@/utils/auth';

const state = {
  configInfo: null
};

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value;
    }
  }
};

const actions = {
  //
  getSSOConfigInfo({ commit }) {
    return fetchSSOConfigInfo().then((res) => {
      commit('CHANGE_SETTING', { configInfo: res.data });
      setSSOConfig(JSON.stringify(res.data));
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
