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

export const testAI = async (title: string, ai_target: string) => {
  const res = await fetch(`${BASE}/api/ai/test`, {
    method: 'POST', headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ title, ai_target }),
  })
  if (!res.ok) throw new Error('AI test failed')
  return res.json() as Promise<{ verdict: string; reason: string }>
}

export const fetchAILog = async (limit = 50, since_id = 0) => {
  const res = await fetch(`${BASE}/api/ai/debug/log?limit=${limit}&since_id=${since_id}`)
  if (!res.ok) throw new Error('Failed to fetch AI log')
  return res.json()
}

export const clearAILog = async () => {
  await fetch(`${BASE}/api/ai/debug/log`, { method: 'DELETE' })
}
