import {defineStore} from "pinia";
import {TokenInfo, UserStore} from "@/types/stores/userStore.ts";

export const useUserStore = defineStore({
    id: 'useUserStore',
    state: (): UserStore => {
        return {
            tokenInfo: undefined
        }
    },
    actions: {
        saveTokenInfo(tokenInfo: TokenInfo) {
            this.tokenInfo = tokenInfo
        },
        async resetUserInfo() {
            this.tokenInfo = undefined;
        }
    },
    getters: {
        getTokenInfo: (state): TokenInfo => state.tokenInfo as TokenInfo,
    },
    persist: {
        key: "useUserStore",
        storage: window.localStorage,
        paths: ["tokenInfo"],
    }
})
