import type { SteamUser } from "@/types/steam"
import { store } from 'tauri-plugin-valtio';
import { DEFAULT_STORE_CONFIG } from '.';

const defaultValue = {
  dir: "C:\\Program Files (x86)\\Steam",
  csDir: "",
  users: [{
    steamID64: "76561198052315353",
    steamID32: "STEAM_0:0:46157676",
    accountName: "wrr",
    personaName: "wrr",
    recent: 0,
    avatar: ""
  }] as SteamUser[],
  isDirValid: false,
  isCsDirValid: false
}
export const steamStore = store('steam', {...defaultValue}, DEFAULT_STORE_CONFIG);

export const setDir = (dir: string) => { steamStore.state.dir = dir }
export const setCsDir = (dir: string) => { steamStore.state.csDir = dir }
export const setUsers = (users: SteamUser[]) => { steamStore.state.users = users }
export const setIsDirValid = (valid: boolean) => { steamStore.state.isDirValid = valid }
export const setIsCsDirValid = (valid: boolean) => { steamStore.state.isCsDirValid = valid }

export const currentUser = () => {
  return steamStore.state.users[0] || defaultValue.users[0]
}

export const resetSteamStore = () => {
  setDir(defaultValue.dir)
  setCsDir(defaultValue.csDir)
  setUsers(defaultValue.users)
  setIsDirValid(defaultValue.isDirValid)
  setIsCsDirValid(defaultValue.isCsDirValid)
}