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

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

export async function fetch(page: number, dateNum?: number): Promise<BrowsingHistories> {
  const params: {[index: string]: number} = { page }
  if (dateNum) {
    params['dateNum'] = dateNum
  }
  const resp = await httpClient.get<Response<BrowsingHistories>>(_url("/getPage"), { params })
  return resp.data.data
}

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

export async function removeAll(): Promise<boolean> {
  const resp = await httpClient.delete<Response<boolean>>(_url("/delByUserId"))
  return resp.data.data
}
