import type { TrumpPost, Candle, BotTrade, BotPerformance } from '@/types' const BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000' async function fetchJson(path: string, init?: RequestInit): Promise { const res = await fetch(`${BASE_URL}/api${path}`, { headers: { 'Content-Type': 'application/json' }, ...init, }) if (!res.ok) throw new Error(`API error ${res.status}: ${path}`) return res.json() as Promise } export async function getPosts(limit = 20, page = 1): Promise { return fetchJson(`/posts?limit=${limit}&page=${page}`) } export async function getPost(id: number): Promise { return fetchJson(`/posts/${id}`) } export async function getPrices(asset: 'BTC' | 'ETH', tf: string): Promise { return fetchJson(`/prices/${asset}?tf=${tf}`) } export async function getTrades(limit = 20, page = 1): Promise { return fetchJson(`/trades?limit=${limit}&page=${page}`) } export async function getPerformance(): Promise { return fetchJson(`/performance`) } export async function subscribe( wallet: string, signature: string, ): Promise<{ success: boolean; message: string }> { return fetchJson<{ success: boolean; message: string }>(`/subscribe`, { method: 'POST', body: JSON.stringify({ wallet, signature }), }) } export async function getUser( wallet: string, ): Promise<{ wallet_address: string; active: boolean; subscribed_at: string | null; hl_api_key_set: boolean; trades: BotTrade[] }> { return fetchJson<{ wallet_address: string; active: boolean; subscribed_at: string | null; hl_api_key_set: boolean; trades: BotTrade[] }>( `/user/${wallet}`, ) }