import { fetchWithAuth } from "./client"; function buildQuery(params: Record): string { const qs = Object.entries(params) .filter(([, v]) => v !== undefined) .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`) .join("&"); return qs ? `?${qs}` : ""; } export interface CitationRecord { id: string; query_id: string; platform: string; cited: boolean; citation_position: number | null; citation_text: string | null; competitor_brands: string[]; confidence: number | null; match_type: string | null; queried_at: string; } export interface CitationListResponse { items: CitationRecord[]; total: number; } export interface PlatformDistribution { platform: string; count: number; } export interface TrendPoint { date: string; count: number; } export interface CitationStats { total_queries: number; total_citations: number; citation_rate: number; avg_position: number | null; platform_distribution: PlatformDistribution[]; trend: TrendPoint[]; } export const citationsApi = { list: (token: string, params?: string) => fetchWithAuth( `/api/v1/citations/${params ? `?${params}` : ""}`, {}, token ) as Promise, getStats: (token: string, brandId?: string, queryId?: string) => fetchWithAuth( `/api/v1/citations/stats${buildQuery({ brand_id: brandId, query_id: queryId })}`, {}, token ) as Promise, };