import { defineStore } from 'pinia' import { accountApi, type Account } from '../services/accountApi' export const useAccountStore = defineStore('server', { state: () => ({ accounts: [] as Account[], initialized: false }), actions: { async fetchAccounts(force = false) { if (!force && this.initialized) return; try { const data = await accountApi.get(); this.accounts = Array.isArray(data) ? data : []; this.initialized = true; } catch (error) { console.error('Failed to fetch accounts:', error); this.accounts = []; } }, updateAccounts(newAccounts: Account[]) { this.accounts = Array.isArray(newAccounts) ? newAccounts : []; } } })