import { create } from 'zustand' import { adaptersApi } from '../api/adapters' import type { AdapterFileConfig } from '../types/adapter' type AdapterStore = { config: AdapterFileConfig isLoading: boolean error: string | null fetchConfig: () => Promise updateConfig: (patch: Partial) => Promise } export const useAdapterStore = create((set) => ({ config: {}, isLoading: false, error: null, fetchConfig: async () => { set({ isLoading: true, error: null }) try { const config = await adaptersApi.getConfig() set({ config, isLoading: false }) } catch (err) { const message = err instanceof Error ? err.message : 'Failed to load config' set({ isLoading: false, error: message }) } }, updateConfig: async (patch) => { // PUT returns the merged masked config — no need for a separate GET const config = await adaptersApi.updateConfig(patch) set({ config }) }, }))