import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
  state() {
    return {
      userId: '',
      token: '',
      username: '',
      userData: {},
      userPlan: 'Free',
    };
  },
  getters: {
    getUsername() {
      return this.username;
    },
    getUserId() {
      return this.userId;
    },
    getUserToken() {
      return this.token;
    },
    getUserIsPaid() {
      return this.userPlan !== 'Free';
    },
    /**
     *
     * @returns {UserExtensionPlan}
     */
    getUserPlan() {
      return this.userPlan;
    },
  },
  actions: {
    setUsername(username) {
      this.username = username;
    },
    setUserToken(token) {
      this.token = token;
    },
    setUserId(userId) {
      this.userId = userId;
    },
    setUserData(userData) {
      this.userData = userData;

      if (userData.extensionPlan) {
        this.userPlan = userData.extensionPlan;
      }
    },
  },
  persist: {
    enabled: true,
    key: 'pinia-persist-user',
  },
});
