import { Prisma, SelectionStatus } from "@prisma/client";

export function normalizeOdds(value: string | number | Prisma.Decimal) {
  const odds = new Prisma.Decimal(value);
  if (odds.lte(1)) {
    throw new Error(`Invalid decimal odds: ${value}`);
  }
  return odds.toDecimalPlaces(6);
}

export function mapSelectionStatus(status: "ACTIVE" | "SUSPENDED") {
  return status === "ACTIVE" ? SelectionStatus.ACTIVE : SelectionStatus.SUSPENDED;
}

export function marketMapper(providerMarketKey: string) {
  const mapping: Record<string, { name: string; type: string }> = {
    "1x2": { name: "1X2", type: "THREE_WAY" },
    match_winner: { name: "Vainqueur", type: "MONEYLINE" },
    double_chance: { name: "Double chance", type: "DOUBLE_CHANCE" },
    total_2_5: { name: "Total 2.5", type: "TOTAL" },
    btts: { name: "Les deux équipes marquent", type: "BOOLEAN" },
    handicap: { name: "Handicap", type: "HANDICAP" },
    correct_score: { name: "Score exact", type: "CORRECT_SCORE" },
    player_props: { name: "Joueurs", type: "PLAYER_PROPS" },
    corners_cards: { name: "Corners et cartons", type: "CORNERS_CARDS" }
  };

  return mapping[providerMarketKey] ?? { name: providerMarketKey, type: "CUSTOM" };
}
