import { request } from '@/utils/request'
import type { Favorite, PageResult } from '@/types'

export function getFavoritesApi(params: { current?: number; size?: number } = {}) {
  return request<PageResult<Favorite>>({
    url: '/api/favorite',
    method: 'GET',
    params
  })
}

export function addFavoriteApi(productId: number) {
  return request<void>({
    url: `/api/favorite/${productId}`,
    method: 'POST'
  })
}

export function cancelFavoriteApi(favoriteId: number) {
  return request<void>({
    url: `/api/favorite/${favoriteId}`,
    method: 'DELETE'
  })
}

export function cancelFavoriteByProductApi(productId: number) {
  return request<void>({
    url: `/api/favorite/product/${productId}`,
    method: 'DELETE'
  })
}

export function checkFavoriteApi(productId: number) {
  return request<boolean>({
    url: '/api/favorite/check',
    method: 'GET',
    params: { productId }
  })
}

export function getFavoriteCountApi() {
  return request<number>({
    url: '/api/favorite/count',
    method: 'GET'
  })
}
