// packages/feature_game_sequence/lib/models/sequence_models.dart

import 'package:service_api/service_api.dart';

enum SequenceButtonId { 
  btn0, btn1, btn2, btn3, 
  btn4, btn5, btn6, btn7, btn8, btn9
}

enum SequenceContentPool {
  number,       // 1, 2, 3...
  letter,       // A, B, C...
  koreanChar,   // 가, 나, 다...
  emoji,        // 이모지
  wordVeg,      // 야채
  wordFruit,    // 과일
  wordItem,     // 사물
  wordNature,   // 자연
  wordPlace,    // 장소
  mixed,        // [🔥 의미적 구분용] 실제로는 컨트롤러에서 섞음
}

class SequenceDifficulty extends GameDifficulty {
  final int levelIndex;
  final int initialLength;
  final int maxGameLength;
  final int buttonsCount;
  final double roundTimeLimit;
  final double presentationSpeed;
  final SequenceContentPool contentPoolType;

  const SequenceDifficulty({
    required this.levelIndex,
    required super.name,
    required super.contextId,
    required this.initialLength,
    required this.maxGameLength,
    required this.buttonsCount,
    required this.roundTimeLimit,
    required this.presentationSpeed,
    required this.contentPoolType,
  });
}

class SequenceDifficulties {
  // --- 콘텐츠 풀 데이터 ---
  static const List<String> pool_Number = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
  static const List<String> pool_Letter = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
  static const List<String> pool_KoreanChar = ["가", "나", "다", "라", "마", "바", "사", "아", "자", "차"];
  static const List<String> pool_Emoji = ["🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯"];
  
  static const List<String> pool_Veg = ["당근", "오이", "가지", "배추", "무", "파", "고추", "마늘", "감자", "양파"];
  static const List<String> pool_Fruit = ["사과", "배", "포도", "수박", "딸기", "참외", "귤", "자두", "복숭아", "감"];
  static const List<String> pool_Item = ["시계", "안경", "모자", "가방", "우산", "신발", "거울", "빗", "수건", "비누"];
  static const List<String> pool_Nature = ["하늘", "구름", "바람", "비", "눈", "해", "달", "별", "꽃", "나무"];
  static const List<String> pool_Place = ["버스", "기차", "학교", "병원", "시장", "공원", "집", "바다", "산", "마트"];

  static List<String> getSymbolPool(SequenceContentPool type) {
    switch (type) {
      case SequenceContentPool.number: return pool_Number;
      case SequenceContentPool.letter: return pool_Letter;
      case SequenceContentPool.koreanChar: return pool_KoreanChar;
      case SequenceContentPool.emoji: return pool_Emoji;
      case SequenceContentPool.wordVeg: return pool_Veg;
      case SequenceContentPool.wordFruit: return pool_Fruit;
      case SequenceContentPool.wordItem: return pool_Item;
      case SequenceContentPool.wordNature: return pool_Nature;
      case SequenceContentPool.wordPlace: return pool_Place;
      default: return pool_Number;
    }
  }

  // [🔥 수정] 15단계 난이도 (Lv 1~9: 단일 테마, Lv 10+: 믹스)
  static final List<SequenceDifficulty> allDifficulties = [
    // --- Phase 1: 기호/숫자 (단일) ---
    const SequenceDifficulty(levelIndex: 1, name: 'Lv. 1: 입문 (숫자/3버튼)', contextId: 'SEQ_L1_NUM', initialLength: 2, maxGameLength: 4, buttonsCount: 3, roundTimeLimit: 20.0, presentationSpeed: 1.5, contentPoolType: SequenceContentPool.number),
    const SequenceDifficulty(levelIndex: 2, name: 'Lv. 2: 초급 (알파벳/4버튼)', contextId: 'SEQ_L2_LETTER', initialLength: 3, maxGameLength: 5, buttonsCount: 4, roundTimeLimit: 15.0, presentationSpeed: 1.2, contentPoolType: SequenceContentPool.letter),
    const SequenceDifficulty(levelIndex: 3, name: 'Lv. 3: 기초 (한글/4버튼)', contextId: 'SEQ_L3_KOR', initialLength: 3, maxGameLength: 7, buttonsCount: 4, roundTimeLimit: 12.0, presentationSpeed: 1.0, contentPoolType: SequenceContentPool.koreanChar),

    // --- Phase 2: 이모지/단어 (단일) ---
    const SequenceDifficulty(levelIndex: 4, name: 'Lv. 4: 중급 (이모지/4버튼)', contextId: 'SEQ_L4_EMOJI', initialLength: 4, maxGameLength: 9, buttonsCount: 4, roundTimeLimit: 10.0, presentationSpeed: 0.9, contentPoolType: SequenceContentPool.emoji),
    const SequenceDifficulty(levelIndex: 5, name: 'Lv. 5: 중급 (야채/6버튼)', contextId: 'SEQ_L5_VEG', initialLength: 4, maxGameLength: 7, buttonsCount: 6, roundTimeLimit: 12.0, presentationSpeed: 0.9, contentPoolType: SequenceContentPool.wordVeg),
    const SequenceDifficulty(levelIndex: 6, name: 'Lv. 6: 숙련 (과일/6버튼)', contextId: 'SEQ_L6_FRUIT', initialLength: 5, maxGameLength: 10, buttonsCount: 6, roundTimeLimit: 10.0, presentationSpeed: 0.8, contentPoolType: SequenceContentPool.wordFruit),

    // --- Phase 3: 단어 심화 (단일) ---
    const SequenceDifficulty(levelIndex: 7, name: 'Lv. 7: 상급 (사물/6버튼)', contextId: 'SEQ_L7_ITEM', initialLength: 5, maxGameLength: 12, buttonsCount: 6, roundTimeLimit: 10.0, presentationSpeed: 0.8, contentPoolType: SequenceContentPool.wordItem),
    const SequenceDifficulty(levelIndex: 8, name: 'Lv. 8: 전문가 (자연/8버튼)', contextId: 'SEQ_L8_NATURE', initialLength: 5, maxGameLength: 10, buttonsCount: 8, roundTimeLimit: 12.0, presentationSpeed: 0.7, contentPoolType: SequenceContentPool.wordNature),
    const SequenceDifficulty(levelIndex: 9, name: 'Lv. 9: 전문가 (장소/8버튼)', contextId: 'SEQ_L9_PLACE', initialLength: 6, maxGameLength: 15, buttonsCount: 8, roundTimeLimit: 10.0, presentationSpeed: 0.7, contentPoolType: SequenceContentPool.wordPlace),

    // --- Phase 4: 마스터 (믹스 - Lv 10부터 시작) ---
    // (contentPoolType은 mixed로 표시하지만 실제로는 Controller에서 처리)
    const SequenceDifficulty(levelIndex: 10, name: 'Lv. 10: 믹스 (8버튼)', contextId: 'SEQ_L10_MIX_8', initialLength: 6, maxGameLength: 20, buttonsCount: 8, roundTimeLimit: 10.0, presentationSpeed: 0.6, contentPoolType: SequenceContentPool.mixed),
    const SequenceDifficulty(levelIndex: 11, name: 'Lv. 11: 믹스 (10버튼)', contextId: 'SEQ_L11_MIX_10', initialLength: 6, maxGameLength: 15, buttonsCount: 10, roundTimeLimit: 10.0, presentationSpeed: 0.6, contentPoolType: SequenceContentPool.mixed),
    const SequenceDifficulty(levelIndex: 12, name: 'Lv. 12: 레전드 (10버튼)', contextId: 'SEQ_L12_LEGEND', initialLength: 7, maxGameLength: 25, buttonsCount: 10, roundTimeLimit: 8.0, presentationSpeed: 0.5, contentPoolType: SequenceContentPool.mixed),

    // --- Phase 5: 신의 영역 (믹스 + 고속) ---
    const SequenceDifficulty(levelIndex: 13, name: 'Lv. 13: 갓모드 (10버튼)', contextId: 'SEQ_L13_GOD', initialLength: 7, maxGameLength: 30, buttonsCount: 10, roundTimeLimit: 6.0, presentationSpeed: 0.4, contentPoolType: SequenceContentPool.mixed),
    const SequenceDifficulty(levelIndex: 14, name: 'Lv. 14: 갓모드 (기억)', contextId: 'SEQ_L14_GOD_MEM', initialLength: 8, maxGameLength: 40, buttonsCount: 10, roundTimeLimit: 5.0, presentationSpeed: 0.4, contentPoolType: SequenceContentPool.mixed),
    const SequenceDifficulty(levelIndex: 15, name: 'Lv. 15: 엔드게임', contextId: 'SEQ_L15_END', initialLength: 8, maxGameLength: 50, buttonsCount: 10, roundTimeLimit: 5.0, presentationSpeed: 0.3, contentPoolType: SequenceContentPool.mixed),
  ];

  static SequenceDifficulty 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]);
  }
}