import httpClient from "@/services/httpClient";
import type { Response } from "@/types/response.types";
import * as urlHelper from "@/libs/url.lib"
import type { Collections } from "@/types/collection.types";

const _url = urlHelper.withPrefix("/gw/user/collect");

/**
 * 收藏文献
 * @param paperId 文献ID
 * @param title 文献标题
 * @returns 收藏的ID
 */
export async function add(paperId: number, title: string, authors: string, units: string): Promise<number> {
  const resp = await httpClient.post<Response<number>>(_url("/add"), {paperId, title, authors, units})
  return resp.data.data
}

export async function remove(id: number): Promise<boolean> {
  const resp = await httpClient.delete<Response<boolean>>(_url(`/del/${id}`))
  return resp.data.data
}

/**
 * 文献是否已经收藏
 * @param paperId 文献ID
 * @returns 收藏ID
 */
export async function isCollected(paperId: number): Promise<number> {
  const resp = await httpClient.get<Response<number>>(_url("/isCollected"), { params: { paperId } })
  return resp.data.data
}

export async function list(page: number): Promise<Collections> {
  const resp = await httpClient.get<Response<Collections>>(_url("/getPage"), { params: { page } })
  return resp.data.data
}
