import { defineStore } from "pinia";
import { UserState } from "@/stores/interface";
import piniaPersistConfig from "@/stores/helper/persist";

export const useUserStore = defineStore({
  id: "atmosphere-user1",
  state: (): UserState => <UserState>({
    token: "",
    userInfo: {},
    asInfo:[]
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token;
    },
    // Set setUserInfo
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
    setAsInfo(asInfo: UserState["asInfo"]) {
      this.asInfo = asInfo;
    },
    // Clear all data
    clearAllData() {
      this.token = "";
      this.userInfo = {};
      this.asInfo = [];
    }
  },
  persist: piniaPersistConfig("atmosphere-user1")
});
