// src/stores/userStore.ts
import { defineStore } from "pinia";
import { Stateuser } from "@/stores/interface";

const useUserStore = defineStore({
  id: "user-store",

  state: (): Stateuser => ({
    username: "",
    password: "",
    tenantNo: ""
  }),

  actions: {
    // 设置用户信息
    setUser(user: Stateuser) {
      this.username = user.username;
      this.password = user.password; // 注意：通常不应保存密码
      this.tenantNo = user.tenantNo;
    },

    // 获取用户信息
    getUser(): Stateuser {
      return {
        username: this.username,
        password: this.password, // 注意安全性
        tenantNo: this.tenantNo
      };
    },

    // 清空用户信息
    clearUser() {
      this.username = "";
      this.password = "";
      this.tenantNo = "";
    }
  }
});

export default useUserStore;
