import type { Favorite } from "@/lib/types" import { httpJson } from "./http" type Paginated = { items: T[] meta: { total: number offset: number limit: number } } export async function listFavorites(): Promise { const res = await httpJson | Favorite[]>("/api/v1/favorites", { cache: "no-store", }) return Array.isArray(res) ? res : res.items } export async function isFavorited( userId: string, targetType: "player" | "shop", targetId: string, ): Promise { const searchParams = new URLSearchParams({ targetType, targetId, }) const res = await httpJson<{ favorited: boolean }>( `/api/v1/users/${encodeURIComponent(userId)}/favorites/check?${searchParams.toString()}`, { cache: "no-store", }, ) return res.favorited } export async function addFavorite(input: { targetType: "player" | "shop" targetId: string }): Promise { await httpJson("/api/v1/favorites", { method: "POST", json: input, cache: "no-store", }) } export async function removeFavorite(favoriteId: string): Promise { await httpJson(`/api/v1/favorites/${encodeURIComponent(favoriteId)}`, { method: "DELETE", cache: "no-store", }) }