const BASE = 'http://localhost:8000'

// GET /api/config returns a flat dict {key: value} — return it directly.
export const fetchConfig = async (): Promise<Record<string, string>> => {
  const res = await fetch(`${BASE}/api/config`)
  if (!res.ok) throw new Error('Failed to fetch config')
  return res.json()
}

// POST /api/config expects a flat dict {key: value} — send data directly.
export const saveConfig = async (data: Record<string, string>): Promise<void> => {
  const res = await fetch(`${BASE}/api/config`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(data),
  })
  if (!res.ok) throw new Error('Failed to save config')
}
