import client from "../client"
import type { ApiResultString, BookAddDto, BookUpdateDto } from "@/types/api"

export async function addBook(data: BookAddDto): Promise<string | null> {
  const res = await client.post<ApiResultString>("/api/admin/books/add", data)
  return res.data.data
}

export async function deleteBook(id: number): Promise<string | null> {
  const res = await client.post<ApiResultString>("/api/admin/books/delete", null, { params: { id } })
  return res.data.data
}

export async function updateBook(id: number, data: BookUpdateDto): Promise<string | null> {
  const res = await client.post<ApiResultString>("/api/admin/books/update", data, { params: { id } })
  return res.data.data
}

export async function updateStock(id: number, stock: number): Promise<string | null> {
  const res = await client.post<ApiResultString>("/api/admin/books/update-stock", null, { params: { id, stock } })
  return res.data.data
}
