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

export const testTelegram = async (): Promise<{ status: string }> => {
  const res = await fetch(`${BASE}/api/telegram/test`, { method: 'POST' })
  if (!res.ok) throw new Error('Telegram test failed')
  return res.json()
}

// File downloads — use window.open, not fetch
export const downloadBackup = () => window.open(`${BASE}/api/backup/download`)

export const restoreBackup = async (file: File): Promise<void> => {
  const form = new FormData()
  form.append('file', file)
  const res = await fetch(`${BASE}/api/backup/restore`, { method: 'POST', body: form })
  if (!res.ok) throw new Error('Restore failed')
}
