/**
 * Game Cloning Templates
 * Pre-built templates for common game types to speed up game generation
 */
export interface GameTemplate {
  id: string;
  name: string;
  description: string;
  category: string;
  baseConfig: {
    reels: number;
    paylines: number;
    minBet: number;
    maxBet: number;
    rtp: number;
    volatility: "low" | "medium" | "high";
  };
  symbols: string[];
  bonusFeatures: string[];
  theme: string;
  assetStyle: string;
  difficulty: "easy" | "medium" | "hard";
}

export class GameCloningTemplates {
  private static templates: Map<string, GameTemplate> = new Map();

  static {
    // Initialize templates
    GameCloningTemplates.initializeTemplates();
  }

  /**
   * Initialize all templates
   */
  private static initializeTemplates(): void {
    // Fruit Slots Template
    this.templates.set("fruit-slots", {
      id: "fruit-slots",
      name: "Fruit Slots",
      description: "Classic fruit-themed slot machine with traditional symbols",
      category: "Classic",
      baseConfig: {
        reels: 3,
        paylines: 5,
        minBet: 0.1,
        maxBet: 100,
        rtp: 96.5,
        volatility: "medium",
      },
      symbols: ["cherry", "lemon", "orange", "plum", "grape", "watermelon", "bell", "seven"],
      bonusFeatures: ["Free Spins", "Multiplier", "Wild Symbol"],
      theme: "Fruit Slots",
      assetStyle: "Colorful 2D",
      difficulty: "easy",
    });

    // Vegas Theme Template
    this.templates.set("vegas-theme", {
      id: "vegas-theme",
      name: "Vegas Nights",
      description: "High-energy Vegas-themed game with neon aesthetics",
      category: "Vegas",
      baseConfig: {
        reels: 5,
        paylines: 25,
        minBet: 0.1,
        maxBet: 500,
        rtp: 95.8,
        volatility: "high",
      },
      symbols: ["diamond", "spade", "heart", "club", "dollar", "neon-sign", "jackpot", "lucky-7"],
      bonusFeatures: ["Bonus Round", "Free Spins", "Multiplier", "Progressive Jackpot"],
      theme: "Vegas",
      assetStyle: "Neon 3D",
      difficulty: "medium",
    });

    // Asian Theme Template
    this.templates.set("asian-theme", {
      id: "asian-theme",
      name: "Lucky Dragon",
      description: "Asian-inspired game with dragons and fortune symbols",
      category: "Asian",
      baseConfig: {
        reels: 5,
        paylines: 20,
        minBet: 0.1,
        maxBet: 200,
        rtp: 96.2,
        volatility: "medium",
      },
      symbols: ["dragon", "phoenix", "lantern", "coin", "pagoda", "lucky-cat", "bamboo", "gold-bar"],
      bonusFeatures: ["Free Spins", "Wild Multiplier", "Bonus Game", "Dragon Respins"],
      theme: "Asian",
      assetStyle: "Traditional Art",
      difficulty: "medium",
    });

    // Holiday Theme Template
    this.templates.set("holiday-theme", {
      id: "holiday-theme",
      name: "Holiday Celebration",
      description: "Festive holiday-themed game with seasonal symbols",
      category: "Holiday",
      baseConfig: {
        reels: 5,
        paylines: 15,
        minBet: 0.1,
        maxBet: 150,
        rtp: 96.8,
        volatility: "low",
      },
      symbols: ["santa", "reindeer", "snowflake", "gift", "tree", "bell", "candy-cane", "snowman"],
      bonusFeatures: ["Free Spins", "Multiplier", "Gift Bonus", "Seasonal Wilds"],
      theme: "Holiday",
      assetStyle: "Festive 3D",
      difficulty: "easy",
    });

    // Ocean Theme Template
    this.templates.set("ocean-theme", {
      id: "ocean-theme",
      name: "Ocean Treasure",
      description: "Underwater adventure with treasure and sea creatures",
      category: "Adventure",
      baseConfig: {
        reels: 5,
        paylines: 30,
        minBet: 0.1,
        maxBet: 300,
        rtp: 96.0,
        volatility: "high",
      },
      symbols: ["mermaid", "octopus", "seahorse", "treasure-chest", "pearl", "anchor", "ship", "coral"],
      bonusFeatures: ["Free Spins", "Expanding Wilds", "Bonus Game", "Treasure Hunt"],
      theme: "Ocean",
      assetStyle: "Underwater 3D",
      difficulty: "hard",
    });

    // Retro Arcade Template
    this.templates.set("retro-arcade", {
      id: "retro-arcade",
      name: "Retro Arcade",
      description: "Nostalgic arcade-style game with pixel art",
      category: "Retro",
      baseConfig: {
        reels: 3,
        paylines: 10,
        minBet: 0.1,
        maxBet: 50,
        rtp: 97.0,
        volatility: "low",
      },
      symbols: ["pac-man", "space-invader", "star", "heart", "coin", "bomb", "gem", "high-score"],
      bonusFeatures: ["Free Spins", "Multiplier", "Arcade Bonus"],
      theme: "Retro",
      assetStyle: "Pixel Art",
      difficulty: "easy",
    });

    // Luxury Theme Template
    this.templates.set("luxury-theme", {
      id: "luxury-theme",
      name: "Luxury Life",
      description: "Upscale luxury-themed game with premium symbols",
      category: "Luxury",
      baseConfig: {
        reels: 5,
        paylines: 40,
        minBet: 1.0,
        maxBet: 1000,
        rtp: 95.5,
        volatility: "high",
      },
      symbols: ["diamond", "yacht", "champagne", "caviar", "gold-watch", "luxury-car", "mansion", "crown"],
      bonusFeatures: ["VIP Bonus", "Luxury Spins", "Premium Multiplier", "Exclusive Jackpot"],
      theme: "Luxury",
      assetStyle: "Premium 3D",
      difficulty: "hard",
    });
  }

  /**
   * Get all templates
   */
  static getAllTemplates(): GameTemplate[] {
    return Array.from(this.templates.values());
  }

  /**
   * Get template by ID
   */
  static getTemplate(templateId: string): GameTemplate | null {
    return this.templates.get(templateId) || null;
  }

  /**
   * Get templates by category
   */
  static getTemplatesByCategory(category: string): GameTemplate[] {
    return Array.from(this.templates.values()).filter((t) => t.category === category);
  }

  /**
   * Get templates by difficulty
   */
  static getTemplatesByDifficulty(difficulty: string): GameTemplate[] {
    return Array.from(this.templates.values()).filter((t) => t.difficulty === difficulty);
  }

  /**
   * Clone template and customize
   */
  static cloneTemplate(
    templateId: string,
    customizations: Partial<GameTemplate>
  ): GameTemplate | null {
    const template = this.getTemplate(templateId);
    if (!template) return null;

    return {
      ...template,
      ...customizations,
      id: `${templateId}-${Date.now()}`,
    };
  }

  /**
   * Get template recommendations based on performance
   */
  static getRecommendedTemplates(performanceData: {
    topTheme?: string;
    targetAudience?: string;
    difficulty?: string;
  }): GameTemplate[] {
    let recommendations = Array.from(this.templates.values());

    if (performanceData.topTheme) {
      recommendations = recommendations.filter((t) => t.theme.toLowerCase().includes(performanceData.topTheme!.toLowerCase()));
    }

    if (performanceData.difficulty) {
      recommendations = recommendations.filter((t) => t.difficulty === performanceData.difficulty);
    }

    return recommendations;
  }

  /**
   * Create custom template
   */
  static createCustomTemplate(template: Omit<GameTemplate, "id">): GameTemplate {
    const newTemplate: GameTemplate = {
      ...template,
      id: `custom-${Date.now()}`,
    };

    this.templates.set(newTemplate.id, newTemplate);
    return newTemplate;
  }

  /**
   * Get categories
   */
  static getCategories(): string[] {
    const categories = new Set<string>();
    this.templates.forEach((t) => categories.add(t.category));
    return Array.from(categories).sort();
  }

  /**
   * Get themes
   */
  static getThemes(): string[] {
    const themes = new Set<string>();
    this.templates.forEach((t) => themes.add(t.theme));
    return Array.from(themes).sort();
  }
}

export default GameCloningTemplates;
