// packages/feature_game_sudoku/lib/models/game_level.dart
import 'package:service_api/service_api.dart'; // 👈 [추가] 공통 모델 import

//
// [🔥 수정] 'extends GameDifficulty' 추가
//
class GameLevel extends GameDifficulty {
  final int levelIndex; // 1-11
  final int blockSize; // 2, 3, 4
  final int generatorLevel; // 서버에 요청할 생성기 난이도 (1~5)

  // ❌ 'name'과 'contextId'는 GameDifficulty가 이미 가지고 있으므로 제거
  // final String name;
  // final String contextId;

  final bool isSequentialNumbers;
  final bool isSequentialLetters;

  const GameLevel({
    required this.levelIndex,
    required super.name, // 👈 [수정] super()로 전달
    required super.contextId, // 👈 [수정] super()로 전달
    required this.blockSize,
    required this.generatorLevel,
    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};
  }
}