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

export const useUserStore = defineStore({
  id: USER_STORE_KEY,
  state: (): UserState => ({
    accessToken: "",
    refreshToken: "",
    isRefreshToken:false,
    userInfo: { name: "admin" },
  }),
  getters: {},
  actions: {
    // Set Token
    setAccessToken(accessToken: string) {
      this.accessToken = accessToken;
    },
    setRefreshToken(refreshToken: string) {
      this.refreshToken = refreshToken;
    },
    setIsRefreshToken(isRefreshToken: boolean) {
      this.isRefreshToken = isRefreshToken;
    },
    // Set setUserInfo
    setUserInfo(userInfo: UserState["userInfo"]) {
      this.userInfo = userInfo;
    },
  },
  persist: piniaPersistConfig(USER_STORE_KEY),
});
