import { apiRequest } from "@/lib/api/client"; export interface ScholarProfile { id: number; scholar_id: string; display_name: string | null; profile_image_url: string | null; profile_image_source: "upload" | "override" | "scraped" | "none"; is_enabled: boolean; baseline_completed: boolean; last_run_dt: string | null; last_run_status: string | null; } export interface ScholarCreatePayload { scholar_id: string; profile_image_url?: string; } export interface ScholarSearchCandidate { scholar_id: string; display_name: string; affiliation: string | null; email_domain: string | null; cited_by_count: number | null; interests: string[]; profile_url: string; profile_image_url: string | null; } export interface ScholarSearchResult { query: string; state: "ok" | "no_results" | "blocked_or_captcha" | "layout_changed" | "network_error"; state_reason: string; action_hint: string | null; candidates: ScholarSearchCandidate[]; warnings: string[]; } interface ScholarsListData { scholars: ScholarProfile[]; } interface ScholarSearchData extends ScholarSearchResult {} export async function listScholars(): Promise { const response = await apiRequest("/scholars", { method: "GET" }); return response.data.scholars; } export async function createScholar(payload: ScholarCreatePayload): Promise { const response = await apiRequest("/scholars", { method: "POST", body: payload, }); return response.data; } export async function toggleScholar(scholarProfileId: number): Promise { const response = await apiRequest(`/scholars/${scholarProfileId}/toggle`, { method: "PATCH", }); return response.data; } export async function deleteScholar(scholarProfileId: number): Promise { await apiRequest<{ message: string }>(`/scholars/${scholarProfileId}`, { method: "DELETE", }); } export async function searchScholarsByName( query: string, limit = 10, ): Promise { const searchParams = new URLSearchParams({ query, limit: String(limit), }); const response = await apiRequest(`/scholars/search?${searchParams.toString()}`, { method: "GET", }); return response.data; } export async function setScholarImageUrl( scholarProfileId: number, imageUrl: string, ): Promise { const response = await apiRequest(`/scholars/${scholarProfileId}/image/url`, { method: "PUT", body: { image_url: imageUrl }, }); return response.data; } export async function uploadScholarImage( scholarProfileId: number, file: File, ): Promise { const form = new FormData(); form.append("image", file); const response = await apiRequest(`/scholars/${scholarProfileId}/image/upload`, { method: "POST", body: form, }); return response.data; } export async function clearScholarImage( scholarProfileId: number, ): Promise { const response = await apiRequest(`/scholars/${scholarProfileId}/image`, { method: "DELETE", }); return response.data; }