import { deleteUserFav, getUserFavList, isUserFav, updateUserFav } from "../dao/FavPlayerDAO";
import { xcxApi } from "../utils/server";

export async function listFavPlayers(aud: string) {
  const uids = await getUserFavList(aud);
  const profiles = uids.map(uid => xcxApi.getAdvProfile(uid));
  return await Promise.all(profiles);
}

export async function favPlayer(aud: string, uid: string) {
  await updateUserFav(aud, uid);
  return await getUserFavList(aud);
};

export async function unFavPlayer(aud: string, uid: string) {
  await deleteUserFav(aud, uid);
  return await getUserFavList(aud);
}

export async function checkIsUserFav(aud: string, uid: string) {
  return await isUserFav(aud, uid);
}