import { api } from "@/lib/api-client";
import type {
  CoursePlan,
  CoursePlanGenerateBrief,
  CoursePlanMaterial,
} from "@/types";

/**
 * REST helpers for the AI course plan generator.
 *
 * The backend routes are mounted under `/api/ai/course-plan`; see
 * `backend/custom_addons/encoach_ai_course/controllers/course_plan.py`.
 */
export const coursePlanService = {
  async list(params?: {
    page?: number;
    size?: number;
    search?: string;
  }): Promise<{ items: CoursePlan[]; page: { page: number; size: number; total: number } }> {
    return api.get("/ai/course-plan", params);
  },

  async get(planId: number): Promise<{ data: CoursePlan }> {
    return api.get(`/ai/course-plan/${planId}`);
  },

  async generate(brief: CoursePlanGenerateBrief): Promise<{ data: CoursePlan }> {
    return api.post("/ai/course-plan", brief);
  },

  async remove(planId: number): Promise<{ success: boolean }> {
    return api.delete(`/ai/course-plan/${planId}`);
  },

  async generateWeekMaterials(
    planId: number,
    weekNumber: number,
  ): Promise<{ items: CoursePlanMaterial[]; count: number }> {
    return api.post(`/ai/course-plan/${planId}/weeks/${weekNumber}/materials`);
  },

  async listWeekMaterials(
    planId: number,
    weekNumber: number,
  ): Promise<{ items: CoursePlanMaterial[]; count: number }> {
    return api.get(`/ai/course-plan/${planId}/weeks/${weekNumber}/materials`);
  },
};
