import { create } from 'zustand';

// 根据设计文档定义配置项的类型
export interface DatabaseConfig {
  url: string;
}

export interface NewApiConfig {
  api_key: string;
  base_url?: string;
}

export interface DataSourceConfig {
  [key: string]: { api_key: string };
}

export interface SystemConfig {
  database: DatabaseConfig;
  new_api: NewApiConfig;
  data_sources: DataSourceConfig;
}

interface ConfigState {
  config: SystemConfig | null;
  loading: boolean;
  error: string | null;
  setConfig: (config: SystemConfig) => void;
  setLoading: (loading: boolean) => void;
  setError: (error: string | null) => void;
}

export const useConfigStore = create<ConfigState>((set) => ({
  config: null,
  loading: true,
  error: null,
  setConfig: (config) => set({ config, loading: false, error: null }),
  setLoading: (loading) => set({ loading }),
  setError: (error) => set({ error, loading: false }),
}));
