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:[],
    stations:[]
  }),
  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;
    },
    setStations(stations: UserState["asInfo"]){
    this.stations = stations;
    },
    // Clear all data
    clearAllData() {
      this.token = "";
      this.userInfo = {};
      this.asInfo = [];
      this.stations =[]
    }
  },
  persist: piniaPersistConfig("atmosphere-user1")
});
