import { createStore } from 'vuex';
import { apiService } from "@/server/api.service"
// 创建 Vuex Store
const store = createStore({
  state: {
    count: 0, // 示例状态
    userInfo: null // 用户信息
  },
  mutations: {
    // 修改状态的方法
    increment(state) {
      state.count++;
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo;
    }
  },
  actions: {
    // 异步操作
    incrementAsync({ commit }) {
      setTimeout(() => {
        commit('increment');
      }, 1000);
    },
    fetchUserInfo({ commit }, userId) {
      // 模拟异步请求
      return new Promise((resolve) => {
        setTimeout(() => {
          const userInfo = { id: userId, name: 'John Doe' };
          commit('setUserInfo', userInfo);
          resolve(userInfo);
        }, 1000);
      });
    }
  },
  getters: {
    // 计算属性
    doubleCount(state) {
      return state.count * 2;
    }
  }
});

export default store;