import { ref, computed } from "vue";
import { defineStore } from "pinia";
import http from "@/plugins/http";

declare interface User {
    id: number;
    username: string;
    visitor: boolean;
    avatar?: string;
    email?: string;
}

export const useUserStore = defineStore("user", () => {
    const user = ref<User | null>(null);
    function setUser(newUser: User | null) {
        user.value = newUser;
    }

    function getUser() {
        http.get("/users/my").then((res) => {
            setUser(res);
        });
    }

    return { user, setUser, getUser };
});
