import { apiFetch } from './authClient'; export type LeetCodeSummary = { username: string; profileURL: string; totalSolved: number; }; async function parseJson(res: Response) { const text = await res.text(); try { return text ? JSON.parse(text) : {}; } catch { return { error: 'Invalid server response' }; } } export async function fetchLeetCodeSummary(profileLink: string): Promise { const res = await apiFetch('/api/integrations/leetcode-summary', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ profileLink }), }); const data = (await parseJson(res)) as LeetCodeSummary & { error?: string }; if (!res.ok) { throw new Error(data.error || 'Failed to fetch LeetCode profile'); } return { username: data.username, profileURL: data.profileURL, totalSolved: data.totalSolved, }; }