import api from "@/api/client";
import type {
  Bookmark,
  CreateMarkerPayload,
  PaginatedResponse,
} from "@/types";

export async function fetchBookmarks(
  ebookId?: string | number,
): Promise<PaginatedResponse<Bookmark>> {
  const params: Record<string, string> = {};
  if (ebookId != null && ebookId !== "") params.ebook = String(ebookId);
  const { data } = await api.get<PaginatedResponse<Bookmark>>(
    "/annotations/bookmarks/",
    { params },
  );
  return data;
}

export async function createMarker(
  payload: CreateMarkerPayload,
): Promise<Bookmark> {
  const { data } = await api.post<Bookmark>("/annotations/bookmarks/", payload);
  return data;
}

export async function deleteBookmark(id: string): Promise<void> {
  await api.delete(`/annotations/bookmarks/${id}/`);
}

/** @deprecated Use createMarker */
export const createBookmark = createMarker;
