import client from "./client"
import type { ApiResultListMyBorrowVo, ApiResultMyBorrowVo, ApiResultString, MyBorrowVo } from "@/types/api"

export async function getAllMyBorrows(): Promise<MyBorrowVo[]> {
  const res = await client.get<ApiResultListMyBorrowVo>("/api/borrows/getall")
  return res.data.data!
}

export async function getOneMyBorrow(borrowId: number): Promise<MyBorrowVo> {
  const res = await client.get<ApiResultMyBorrowVo>("/api/borrows/getone", { params: { borrowId } })
  return res.data.data!
}

export async function searchMyBorrows(query: string): Promise<MyBorrowVo[]> {
  const res = await client.get<ApiResultListMyBorrowVo>("/api/borrows/search", { params: { query } })
  return res.data.data!
}

export async function borrowBookForMe(bookId: number): Promise<string | null> {
  const res = await client.post<ApiResultString>("/api/borrows/borrowbook", null, { params: { bookId } })
  return res.data.data
}

export async function returnBookForMe(borrowId: number): Promise<string | null> {
  const res = await client.post<ApiResultString>("/api/borrows/returnbook", null, { params: { borrowId } })
  return res.data.data
}
