// packages/feature_game_spider/lib/models/spider_difficulty.dart

import 'package:service_api/service_api.dart'; // 👈 공통 GameDifficulty 모델

/// 스파이더 게임의 난이도 정의
class SpiderDifficulty extends GameDifficulty {
  /// 레벨 순서 (1-9)
  final int levelIndex;
  
  /// 무늬 수 (1, 2, 4)
  final int numSuits;
  
  /// 카드 분배 문자열 (예: "4,3")
  final String numCardsDistribution;

  const SpiderDifficulty({
    required this.levelIndex,
    required super.name,
    required super.contextId,
    required this.numSuits,
    required this.numCardsDistribution,
  });
}

/// 앱 전역에서 사용할 스파이더 난이도 목록 (총 9개)
/// (스도쿠의 AppLevels와 동일한 구조)
class SpiderDifficulties {
  static final List<SpiderDifficulty> allDifficulties = [
    // --- 1 Suit (Easy) ---
    const SpiderDifficulty(
      levelIndex: 1,
      name: '입문 (1 Suit)',
      contextId: 'SPIDER_L1_1SUIT_4-3',
      numSuits: 1,
      numCardsDistribution: '4,3',
    ),
    const SpiderDifficulty(
      levelIndex: 2,
      name: '초급 (1 Suit)',
      contextId: 'SPIDER_L2_1SUIT_5-4',
      numSuits: 1,
      numCardsDistribution: '5,4',
    ),
    const SpiderDifficulty(
      levelIndex: 3,
      name: '중급 (1 Suit)',
      contextId: 'SPIDER_L3_1SUIT_6-5',
      numSuits: 1,
      numCardsDistribution: '6,5',
    ),
    
    // --- 2 Suits (Medium) ---
    const SpiderDifficulty(
      levelIndex: 4,
      name: '상급 (2 Suits)',
      contextId: 'SPIDER_L4_2SUITS_5-4',
      numSuits: 2,
      numCardsDistribution: '5,4',
    ),
    const SpiderDifficulty(
      levelIndex: 5,
      name: '전문가 (2 Suits)',
      contextId: 'SPIDER_L5_2SUITS_6-5',
      numSuits: 2,
      numCardsDistribution: '6,5',
    ),
    const SpiderDifficulty(
      levelIndex: 6,
      name: '마스터 (2 Suits)',
      contextId: 'SPIDER_L6_2SUITS_7-6',
      numSuits: 2,
      numCardsDistribution: '7,6',
    ),
    
    // --- 4 Suits (Hard) ---
    const SpiderDifficulty(
      levelIndex: 7,
      name: '최상급 (4 Suits)',
      contextId: 'SPIDER_L7_4SUITS_6-5',
      numSuits: 4,
      numCardsDistribution: '6,5',
    ),
    const SpiderDifficulty(
      levelIndex: 8,
      name: '지옥 (4 Suits)',
      contextId: 'SPIDER_L8_4SUITS_7-6',
      numSuits: 4,
      numCardsDistribution: '7,6',
    ),
    const SpiderDifficulty(
      levelIndex: 9,
      name: '챔피언 (4 Suits)',
      contextId: 'SPIDER_L9_4SUITS_8-7',
      numSuits: 4,
      numCardsDistribution: '8,7',
    ),
  ];

  /// 레벨 인덱스(1-9)로 레벨 정보 찾기
  static SpiderDifficulty getLevel(int levelIndex) {
    if (levelIndex < 1) levelIndex = 1;
    if (levelIndex > allDifficulties.length) levelIndex = allDifficulties.length;
    return allDifficulties.firstWhere((level) => level.levelIndex == levelIndex,
        orElse: () => allDifficulties[0]
    );
  }

  /// 랭킹 화면용 맵 (ContextId -> 이름)
  static Map<String, String> get contextIdToNameMap {
    return { for (var level in allDifficulties) level.contextId : level.name };
  }
}