// packages/feature_game_sudoku/lib/models/game_level.dart
// (이 파일은 service_api에서 이동해 옴)

class GameLevel {
  final int levelIndex; // 1-11
  final String name; // "입문 (4x4)"
  final int blockSize; // 2, 3, 4
  final int generatorLevel; // 서버에 요청할 생성기 난이도 (1~5)
  final String contextId; // 랭킹 ID "SUDOKU_4x4_L1"
  
  final bool isSequentialNumbers;
  final bool isSequentialLetters;

  const GameLevel({
    required this.levelIndex,
    required this.name,
    required this.blockSize,
    required this.generatorLevel,
    required this.contextId,
    this.isSequentialNumbers = false,
    this.isSequentialLetters = false,
  });
}

class AppLevels {
  static final List<GameLevel> allLevels = [
    // --- 2x2 (blockSize = 2) ---
    const GameLevel(
      levelIndex: 1, name: "입문 (4x4)", blockSize: 2, generatorLevel: 1, 
      contextId: "SUDOKU_4x4_L1", isSequentialNumbers: true
    ),
    const GameLevel(
      levelIndex: 2, name: "초급 (4x4)", blockSize: 2, generatorLevel: 3, 
      contextId: "SUDOKU_4x4_L3", isSequentialLetters: true
    ),
    const GameLevel(
      levelIndex: 3, name: "숙련 (4x4)", blockSize: 2, generatorLevel: 5, 
      contextId: "SUDOKU_4x4_L5"
    ),
    
    // --- 3x3 (blockSize = 3) ---
    const GameLevel(
      levelIndex: 4, name: "쉬움 (9x9)", blockSize: 3, generatorLevel: 1, 
      contextId: "SUDOKU_9x9_L1", isSequentialNumbers: true
    ),
    const GameLevel(
      levelIndex: 5, name: "중급 (9x9)", blockSize: 3, generatorLevel: 2, 
      contextId: "SUDOKU_9x9_L2", isSequentialLetters: true
    ),
    const GameLevel(
      levelIndex: 6, name: "상급 (9x9)", blockSize: 3, generatorLevel: 3, 
      contextId: "SUDOKU_9x9_L3"
    ),
    const GameLevel(
      levelIndex: 7, name: "어려움 (9x9)", blockSize: 3, generatorLevel: 4, 
      contextId: "SUDOKU_9x9_L4"
    ),
    const GameLevel(
      levelIndex: 8, name: "최상급 (9x9)", blockSize: 3, generatorLevel: 5, 
      contextId: "SUDOKU_9x9_L5"
    ),

    // --- 4x4 (blockSize = 4) ---
    const GameLevel(
      levelIndex: 9, name: "전문가 (16x16)", blockSize: 4, generatorLevel: 1, 
      contextId: "SUDOKU_16x16_L1", isSequentialNumbers: true
    ),
    const GameLevel(
      levelIndex: 10, name: "마스터 (16x16)", blockSize: 4, generatorLevel: 3, 
      contextId: "SUDOKU_16x16_L3", isSequentialLetters: true
    ),
    const GameLevel(
      levelIndex: 11, name: "지옥 (16x16)", blockSize: 4, generatorLevel: 5, 
      contextId: "SUDOKU_16x16_L5"
    ),
  ];

  static GameLevel getLevel(int levelIndex) {
    if (levelIndex < 1) levelIndex = 1;
    if (levelIndex > allLevels.length) levelIndex = allLevels.length;
    return allLevels.firstWhere((level) => level.levelIndex == levelIndex,
        orElse: () => allLevels[0]
    );
  }

  static Map<String, String> get contextIdToNameMap {
    return { for (var level in allLevels) level.contextId : level.name };
  }
}