/**
 * Dragon's Fury - HTML5 Slot Game
 * Hold & Spin mechanics with dragon theme and massive multipliers
 */

import { HTML5GameConfig, createHTML5Game } from '../html5GameTemplate.ts';

export const dragonsFuryConfig: HTML5GameConfig = {
  id: 'dragons-fury',
  name: "Dragon's Fury",
  description: 'Hold & Spin game with dragon theme and massive multipliers',
  thumbnail: '🐉',
  rtp: 95.8,
  volatility: 'high',
  minBet: 0.1,
  maxBet: 100,
  reels: 5,
  rows: 3,
  paylines: 25,
  symbols: [
    {
      id: 'dragon-egg',
      name: 'Dragon Egg',
      emoji: '🥚',
      payouts: { 5: 100, 4: 30, 3: 10 },
    },
    {
      id: 'dragon-fire',
      name: 'Dragon Fire',
      emoji: '🔥',
      payouts: { 5: 200, 4: 50, 3: 15 },
    },
    {
      id: 'dragon-treasure',
      name: 'Dragon Treasure',
      emoji: '💰',
      payouts: { 5: 500, 4: 100, 3: 30 },
    },
    {
      id: 'dragon-crown',
      name: 'Dragon Crown',
      emoji: '👑',
      payouts: { 5: 750, 4: 150, 3: 50 },
    },
    {
      id: 'dragon-head',
      name: 'Dragon Head',
      emoji: '🐲',
      payouts: { 5: 1000, 4: 250, 3: 75 },
      isWild: true,
    },
    {
      id: 'dragon-gold',
      name: 'Dragon Gold',
      emoji: '⭐',
      payouts: { 5: 5000, 4: 1000, 3: 200 },
      isScatter: true,
    },
  ],
  features: [
    {
      name: 'Hold & Spin',
      description: 'Hold symbols and respin for more matches',
      triggerCondition: 'After any win',
    },
    {
      name: 'Multiplier Stack',
      description: 'Each hold increases multiplier by 2x',
      triggerCondition: 'During hold & spin',
    },
    {
      name: 'Dragon Wild',
      description: 'Dragon Head expands to fill entire reel',
      triggerCondition: 'Random',
    },
    {
      name: 'Fury Bonus',
      description: 'Get 3+ Dragon Gold for massive bonus',
      triggerCondition: 'Scatter symbol',
    },
  ],
  bonusRounds: [
    {
      id: 'dragon-fury-bonus',
      name: 'Dragon Fury Bonus',
      type: 'pick_em',
      triggerSymbol: 'dragon-gold',
      triggerCount: 3,
      reward: 50,
    },
    {
      id: 'dragon-respin',
      name: 'Dragon Respin',
      type: 'respin',
      triggerSymbol: 'dragon-head',
      triggerCount: 2,
      reward: 10,
    },
  ],
};

/**
 * Create Dragon's Fury game instance
 */
export function createDragonsFuryGame() {
  return createHTML5Game(dragonsFuryConfig);
}

/**
 * Dragon's Fury specific features
 */
export const dragonsFuryFeatures = {
  holdAndSpin: {
    enabled: true,
    maxHolds: 5,
    multiplierIncrease: 2,
    respinCount: 3,
  },
  dragonWild: {
    enabled: true,
    expandable: true,
    symbol: 'dragon-head',
  },
  furyBonus: {
    enabled: true,
    triggerCount: 3,
    baseReward: 50,
    maxReward: 500,
  },
  progressiveJackpot: {
    enabled: true,
    startAmount: 5000,
    contributionPercentage: 0.5,
  },
};

/**
 * Calculate Dragon's Fury win with hold & spin multiplier
 */
export function calculateDragonsFuryWin(
  baseWin: number,
  holdCount: number,
  isBonus: boolean
): {
  baseWin: number;
  holdMultiplier: number;
  bonusMultiplier: number;
  totalWin: number;
} {
  const holdMultiplier = 1 + holdCount * dragonsFuryFeatures.holdAndSpin.multiplierIncrease;
  const bonusMultiplier = isBonus ? 3 : 1;
  const totalWin = baseWin * holdMultiplier * bonusMultiplier;

  return {
    baseWin,
    holdMultiplier,
    bonusMultiplier,
    totalWin,
  };
}
