import { apiClient } from "@/lib/api-client" import type { PaginatedResponse, ApiResponse } from "@/types/api" import type { SkillTreeChapter, SkillTreeFormData } from "@/types/skill-tree" export interface FetchChaptersParams { page?: number limit?: number categoryId?: string } export async function fetchChapters( params: FetchChaptersParams = {} ): Promise> { const searchParams = new URLSearchParams() if (params.page) searchParams.set("page", String(params.page)) if (params.limit) searchParams.set("limit", String(params.limit)) if (params.categoryId) searchParams.set("categoryId", params.categoryId) return apiClient .get("skill-tree", { searchParams }) .json>() } export async function createChapter( data: SkillTreeFormData ): Promise> { return apiClient.post("skill-tree", { json: data }).json>() } export async function updateChapter( id: string, data: Partial ): Promise> { return apiClient .put(`skill-tree/${id}`, { json: data }) .json>() } export async function deleteChapter(id: string): Promise> { return apiClient.delete(`skill-tree/${id}`).json>() } export async function reorderChapters( items: { id: string; sortOrder: number }[] ): Promise> { return apiClient .patch("skill-tree/reorder", { json: { items } }) .json>() }