import type { MarketCall, CalendarEvent, ScreenerResult } from '$lib/types.js'; import { authFetch } from './auth.js'; const BASE = '/api'; export async function fetchCalls(): Promise<{ calls: MarketCall[] }> { const res = await fetch(`${BASE}/calls`); if (!res.ok) throw new Error(await res.text()); return res.json(); } export async function fetchCall(id: string): Promise { const res = await fetch(`${BASE}/calls/${id}`); if (!res.ok) throw new Error(await res.text()); return res.json(); } export async function createCall(payload: { title: string; quarter: string; thesis: string; tickers: string[]; date?: string; }): Promise { const res = await authFetch(`${BASE}/calls`, { method: 'POST', body: JSON.stringify(payload), }); if (!res.ok) throw new Error(await res.text()); return res.json(); } export async function deleteCall(id: string): Promise<{ ok: boolean }> { const res = await authFetch(`${BASE}/calls/${id}`, { method: 'DELETE' }); if (!res.ok) throw new Error(await res.text()); return res.json(); } export async function fetchCallsCalendar( tickers: string[] | null = null, ): Promise<{ events: CalendarEvent[] }> { const url = tickers?.length ? `${BASE}/calls/calendar?tickers=${tickers.join(',')}` : `${BASE}/calls/calendar`; const res = await fetch(url); if (!res.ok) throw new Error(await res.text()); return res.json(); }