import { defineStore } from "pinia";
import { v4 as uuid } from 'uuid'

export const usePlayerStore = defineStore("player", {
    state: () => ({
        id: null,
        username: "Anonimus",
        createdAt: null,
        
    }),
    getters: {
        getId(state) {
            if (state.id == null) usePlayerStore().init();
            return state.id
        }
    },
    actions: {
        init() {
            if (this.id == null) {
                this.id = uuid()
                this.username = 'Anonimus'
                this.createdAt = new Date()
            }
        },
    },
    persist: true,
});
