import { api } from "@/lib/api-client";

interface CoachChatRequest {
  message: string;
  history?: { role: string; content: string }[];
  context?: unknown;
}

interface CoachChatResponse {
  reply: string;
}

interface CoachTipResponse {
  tip: string;
  category: string;
}

interface CoachSuggestResponse {
  suggestion: string;
  focus_areas: string[];
  daily_plan: { activity: string; duration_min: number; skill: string }[];
  motivation: string;
}

interface CoachWritingResponse {
  improved_text: string;
  changes: { original: string; revised: string; reason: string }[];
  tips: string[];
}

export const coachingService = {
  async chat(data: CoachChatRequest): Promise<CoachChatResponse> {
    return api.post<CoachChatResponse>("/coach/chat", data);
  },

  async getHint(data: { topic_id: number; question_id: string }): Promise<{ hint: string; strategy: string }> {
    return api.post("/coach/hint", data);
  },

  async explain(data: { score_data: Record<string, unknown>; student_context?: string }): Promise<{ explanation: string }> {
    return api.post("/coach/explain", data);
  },

  async suggest(data?: Record<string, unknown>): Promise<CoachSuggestResponse> {
    return api.post("/coach/suggest", data);
  },

  async writingHelp(data: { task: string; draft: string; help_type: string }): Promise<CoachWritingResponse> {
    return api.post("/coach/writing-help", data);
  },

  async getTip(context: string): Promise<CoachTipResponse> {
    return api.get<CoachTipResponse>("/coach/tip", { context });
  },
};
