import { api } from "@/lib/api-client";
import type { AiInsight, AiAlert, AiSearchResult, AiBatchOptimization, AiGradingResult } from "@/types";

export const analyticsService = {
  async getStudentAnalytics(params?: Record<string, string | number | boolean | undefined>): Promise<unknown> {
    return api.get("/analytics/student", params);
  },

  async getClassAnalytics(params?: Record<string, string | number | boolean | undefined>): Promise<unknown> {
    return api.get("/analytics/class", params);
  },

  async getSubjectAnalytics(params?: Record<string, string | number | boolean | undefined>): Promise<unknown> {
    return api.get("/analytics/subject", params);
  },

  async getContentGaps(params?: { subject_id?: number }): Promise<{ gaps: { topic_id: number; topic_name: string; resource_count: number }[] }> {
    return api.get("/analytics/content-gaps", params as Record<string, string | number | boolean | undefined>);
  },

  async search(query: string): Promise<AiSearchResult[]> {
    return api.post<AiSearchResult[]>("/ai/search", { query });
  },

  async getInsights(data: Record<string, unknown>): Promise<AiInsight[]> {
    return api.post<AiInsight[]>("/ai/insights", data);
  },

  async getAlerts(): Promise<AiAlert[]> {
    return api.get<AiAlert[]>("/ai/alerts");
  },

  async getReportNarrative(data: { report_type: string; data: Record<string, unknown> }): Promise<{ narrative: string }> {
    return api.post("/ai/report-narrative", data);
  },

  async getBatchOptimization(batchId: number): Promise<AiBatchOptimization[]> {
    return api.post<AiBatchOptimization[]>("/ai/batch-optimize", { batch_id: batchId });
  },

  async getGradingSuggestion(data: { submission_id: number; text: string; rubric_id?: number }): Promise<AiGradingResult> {
    return api.post<AiGradingResult>("/ai/grade-suggest", data);
  },
};
