import type { MarketContext, PortfolioHolding, PortfolioAdvice } from '$lib/types.js'; import { authFetch } from './auth.js'; const BASE = '/api'; export async function fetchPortfolio(): Promise<{ advice: PortfolioAdvice[]; holdings: PortfolioHolding[]; marketContext: MarketContext | null; netWorth: number | null; error?: string; }> { const res = await authFetch(`${BASE}/finance/portfolio`); if (!res.ok) throw new Error(await res.text()); return res.json(); } export async function addHolding( holding: PortfolioHolding, ): Promise<{ holdings: PortfolioHolding[] }> { const res = await authFetch(`${BASE}/finance/holdings`, { method: 'POST', body: JSON.stringify(holding), }); if (!res.ok) throw new Error(await res.text()); return res.json(); } export async function removeHolding(ticker: string): Promise<{ holdings: PortfolioHolding[] }> { const res = await authFetch(`${BASE}/finance/holdings/${ticker}`, { method: 'DELETE' }); if (!res.ok) throw new Error(await res.text()); return res.json(); } export async function fetchMarketContext(): Promise { const res = await authFetch(`${BASE}/finance/market-context`); if (!res.ok) throw new Error(await res.text()); return res.json(); }