import { ref } from "vue";
import { defineStore } from "pinia";
import type { UserInfo } from "@/types/user";

export const useUserStore = defineStore(
  "user",
  () => {
    const token = ref<string>("");
    const userInfo = ref<UserInfo | null>(null);

    const setToken = (newToken: string) => {
      token.value = newToken;
    };

    const setUserInfo = (info: UserInfo) => {
      userInfo.value = info;
    };

    const clearUserInfo = () => {
      token.value = "";
      userInfo.value = null;
    };

    return {
      token,
      userInfo,
      setToken,
      setUserInfo,
      clearUserInfo,
    };
  },
  {
    persist: true,
  },
);
