import client from "./client"
import type { ApiResultBook, ApiResultListBook } from "@/types/api"
import type { Book } from "@/types/api"

export async function getAllBooks(): Promise<Book[]> {
  const res = await client.get<ApiResultListBook>("/api/books/getall")
  return res.data.data!
}

export async function getOneBook(id: number): Promise<Book> {
  const res = await client.get<ApiResultBook>("/api/books/getone", { params: { id } })
  return res.data.data!
}

export async function searchBook(query: string): Promise<Book[]> {
  const res = await client.get<ApiResultListBook>("/api/books/search", { params: { query } })
  return res.data.data!
}
