import type { Service, Heartbeat, ServiceStats } from './types'; const BASE = '/api'; export async function listServices(): Promise { const res = await fetch(`${BASE}/services`); if (!res.ok) throw new Error('falha ao listar serviços'); return res.json(); } export async function createService(data: { name: string; url: string }): Promise { const res = await fetch(`${BASE}/services`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); if (!res.ok) { const err = await res.json().catch(() => ({})); throw new Error(err.error || 'falha ao criar serviço'); } return res.json(); } export async function deleteService(id: number): Promise { const res = await fetch(`${BASE}/services/${id}`, { method: 'DELETE' }); if (!res.ok) throw new Error('falha ao remover serviço'); } export async function getHistory(id: number): Promise { const res = await fetch(`${BASE}/services/${id}/history`); if (!res.ok) throw new Error('falha ao obter histórico'); return res.json(); } export async function getServiceStats(id: number): Promise { const res = await fetch(`${BASE}/services/${id}/stats`); if (!res.ok) throw new Error('falha ao obter estatísticas'); return res.json(); }