import type { CardTier, DailyQuiz } from "@prisma/client";

export const CARD_TIER_LABELS: Record<CardTier, string> = {
  GOLD: "طلایی",
  SILVER: "نقره ای",
  BRONZE: "برنزی",
};

export const CARD_TIER_ORDER: CardTier[] = ["GOLD", "SILVER", "BRONZE"];

export function resolveQuizRewardTier(
  quiz: Pick<DailyQuiz, "goldMinCorrect" | "silverMinCorrect" | "bronzeMinCorrect">,
  correctAnswers: number
): CardTier | null {
  if (quiz.goldMinCorrect != null && correctAnswers >= quiz.goldMinCorrect) {
    return "GOLD";
  }

  if (quiz.silverMinCorrect != null && correctAnswers >= quiz.silverMinCorrect) {
    return "SILVER";
  }

  if (quiz.bronzeMinCorrect != null && correctAnswers >= quiz.bronzeMinCorrect) {
    return "BRONZE";
  }

  return null;
}

export function getCardTierBadgeClass(cardTier: CardTier) {
  switch (cardTier) {
    case "GOLD":
      return "bg-yellow-100 text-yellow-800";
    case "SILVER":
      return "bg-slate-200 text-slate-800";
    case "BRONZE":
      return "bg-amber-100 text-amber-800";
  }
}
