import 'package:asciineverdie/src/core/model/class_traits.dart';
import 'package:asciineverdie/src/core/model/race_traits.dart';

/// 클래스 데이터 정의 (class data)
///
/// 프로그래밍 테마의 18가지 클래스 정의
/// pq_config_data.dart의 Klasses 데이터 기반
class ClassData {
  ClassData._();

  // ==========================================================================
  // 전사 계열 (STR 기반)
  // ==========================================================================

  /// Bug Hunter: STR + INT (스탯 합계: +3)
  static const bugHunter = ClassTraits(
    classId: 'bug_hunter',
    name: 'Bug Hunter',
    statModifiers: {StatType.str: 2, StatType.intelligence: 1},
    startingSkills: ['power_strike'],
    classSkills: ['power_strike', 'execute', 'bug_smash'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.physicalDamageBonus,
        value: 0.10,
        description: '물리 공격 +10%',
      ),
    ],
    restriction: EquipmentRestriction.none,
  );

  /// Overflow Warrior: STR + CON (스탯 합계: +3)
  static const overflowWarrior = ClassTraits(
    classId: 'overflow_warrior',
    name: 'Overflow Warrior',
    statModifiers: {StatType.str: 2, StatType.con: 1},
    startingSkills: ['power_strike'],
    classSkills: ['power_strike', 'overflow_slash', 'buffer_break'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.physicalDamageBonus,
        value: 0.15,
        description: '물리 공격 +15%',
      ),
    ],
    restriction: EquipmentRestriction.none,
  );

  /// Stack Crusher: STR + CON (스탯 합계: +3)
  static const stackCrusher = ClassTraits(
    classId: 'stack_crusher',
    name: 'Stack Crusher',
    statModifiers: {StatType.str: 2, StatType.con: 1},
    startingSkills: ['power_strike'],
    classSkills: ['power_strike', 'stack_smash', 'heap_slam'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.physicalDamageBonus,
        value: 0.10,
        description: '물리 공격 +10%',
      ),
      ClassPassive(
        type: ClassPassiveType.hpBonus,
        value: 0.05,
        description: 'HP +5%',
      ),
    ],
    restriction: EquipmentRestriction.none,
  );

  /// Assertion Knight: STR + WIS (스탯 합계: +3)
  static const assertionKnight = ClassTraits(
    classId: 'assertion_knight',
    name: 'Assertion Knight',
    statModifiers: {StatType.str: 2, StatType.wis: 1},
    startingSkills: ['shield_bash'],
    classSkills: ['shield_bash', 'assert_strike', 'validation_guard'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.defenseBonus,
        value: 0.10,
        description: '방어력 +10%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.heavy),
  );

  // ==========================================================================
  // 탱커 계열 (CON 기반)
  // ==========================================================================

  /// Debugger Paladin: WIS + CON (스탯 합계: +3)
  static const debuggerPaladin = ClassTraits(
    classId: 'debugger_paladin',
    name: 'Debugger Paladin',
    statModifiers: {StatType.wis: 2, StatType.con: 1},
    startingSkills: ['shield_bash'],
    classSkills: ['shield_bash', 'debug_heal', 'breakpoint_guard'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.defenseBonus,
        value: 0.10,
        description: '방어력 +10%',
      ),
      ClassPassive(
        type: ClassPassiveType.healingBonus,
        value: 0.10,
        description: '회복력 +10%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.heavy),
  );

  /// Loop Breaker: CON + STR (스탯 합계: +3)
  static const loopBreaker = ClassTraits(
    classId: 'loop_breaker',
    name: 'Loop Breaker',
    statModifiers: {StatType.con: 2, StatType.str: 1},
    startingSkills: ['shield_bash'],
    classSkills: ['shield_bash', 'infinite_guard', 'break_stance'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.hpBonus,
        value: 0.15,
        description: 'HP +15%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.heavy),
  );

  /// Garbage Collector: CON + STR (스탯 합계: +3)
  static const garbageCollector = ClassTraits(
    classId: 'garbage_collector',
    name: 'Garbage Collector',
    statModifiers: {StatType.con: 2, StatType.str: 1},
    startingSkills: ['absorb'],
    classSkills: ['absorb', 'recycle', 'memory_sweep'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.hpBonus,
        value: 0.20,
        description: 'HP +20%',
      ),
      ClassPassive(
        type: ClassPassiveType.postCombatHeal,
        value: 0.05,
        description: '전투 후 HP 5% 회복',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.heavy),
  );

  // ==========================================================================
  // 마법사 계열 (INT 기반)
  // ==========================================================================

  /// Compiler Mage: INT + WIS (스탯 합계: +3)
  static const compilerMage = ClassTraits(
    classId: 'compiler_mage',
    name: 'Compiler Mage',
    statModifiers: {StatType.intelligence: 2, StatType.wis: 1},
    startingSkills: ['fireball'],
    classSkills: ['fireball', 'compile_blast', 'syntax_storm'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.magicDamageBonus,
        value: 0.15,
        description: '마법 데미지 +15%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// Recursion Master: INT + DEX (스탯 합계: +3)
  static const recursionMaster = ClassTraits(
    classId: 'recursion_master',
    name: 'Recursion Master',
    statModifiers: {StatType.intelligence: 2, StatType.dex: 1},
    startingSkills: ['fireball'],
    classSkills: ['fireball', 'recursive_bolt', 'stack_overflow'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.magicDamageBonus,
        value: 0.20,
        description: '마법 데미지 +20%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// Memory Leaker: INT + WIS (스탯 합계: +3)
  static const memoryLeaker = ClassTraits(
    classId: 'memory_leaker',
    name: 'Memory Leaker',
    statModifiers: {StatType.intelligence: 2, StatType.wis: 1},
    startingSkills: ['fireball'],
    classSkills: ['fireball', 'leak_drain', 'memory_corrupt'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.magicDamageBonus,
        value: 0.10,
        description: '마법 데미지 +10%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// Type Caster: INT + CHA (스탯 합계: +3)
  static const typeCaster = ClassTraits(
    classId: 'type_caster',
    name: 'Type Caster',
    statModifiers: {StatType.intelligence: 2, StatType.cha: 1},
    startingSkills: ['fireball'],
    classSkills: ['fireball', 'type_coercion', 'cast_spell'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.magicDamageBonus,
        value: 0.10,
        description: '마법 데미지 +10%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// DevOps Shaman: CON + INT (스탯 합계: +3)
  static const devOpsShaman = ClassTraits(
    classId: 'devops_shaman',
    name: 'DevOps Shaman',
    statModifiers: {StatType.con: 1, StatType.intelligence: 2},
    startingSkills: ['fireball'],
    classSkills: ['fireball', 'deploy_strike', 'ci_cd_flow'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.magicDamageBonus,
        value: 0.05,
        description: '마법 데미지 +5%',
      ),
      ClassPassive(
        type: ClassPassiveType.hpBonus,
        value: 0.10,
        description: 'HP +10%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  // ==========================================================================
  // 민첩 계열 (DEX 기반)
  // ==========================================================================

  /// Refactor Monk: DEX + CON (스탯 합계: +3)
  static const refactorMonk = ClassTraits(
    classId: 'refactor_monk',
    name: 'Refactor Monk',
    statModifiers: {StatType.dex: 2, StatType.con: 1},
    startingSkills: ['flurry'],
    classSkills: ['flurry', 'clean_code_strike', 'refactor_combo'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.evasionBonus,
        value: 0.10,
        description: '회피율 +10%',
      ),
      ClassPassive(
        type: ClassPassiveType.multiAttack,
        value: 1.0,
        description: '연속 공격',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// Pointer Assassin: DEX + STR (스탯 합계: +3)
  static const pointerAssassin = ClassTraits(
    classId: 'pointer_assassin',
    name: 'Pointer Assassin',
    statModifiers: {StatType.dex: 2, StatType.str: 1},
    startingSkills: ['backstab'],
    classSkills: ['backstab', 'null_strike', 'dereference_kill'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.criticalBonus,
        value: 0.15,
        description: '크리티컬 +15%',
      ),
      ClassPassive(
        type: ClassPassiveType.firstStrikeBonus,
        value: 1.5,
        description: '첫 공격 1.5배',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// Callback Samurai: DEX + STR (스탯 합계: +3)
  static const callbackSamurai = ClassTraits(
    classId: 'callback_samurai',
    name: 'Callback Samurai',
    statModifiers: {StatType.dex: 2, StatType.str: 1},
    startingSkills: ['power_strike'],
    classSkills: ['power_strike', 'async_slash', 'promise_blade'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.criticalBonus,
        value: 0.10,
        description: '크리티컬 +10%',
      ),
      ClassPassive(
        type: ClassPassiveType.physicalDamageBonus,
        value: 0.05,
        description: '물리 공격 +5%',
      ),
    ],
    restriction: EquipmentRestriction.none,
  );

  /// Tester Jester: DEX + CHA (스탯 합계: +3)
  static const testerJester = ClassTraits(
    classId: 'tester_jester',
    name: 'Tester Jester',
    statModifiers: {StatType.dex: 2, StatType.cha: 1},
    startingSkills: ['flurry'],
    classSkills: ['flurry', 'mock_strike', 'assert_fail'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.evasionBonus,
        value: 0.10,
        description: '회피율 +10%',
      ),
      ClassPassive(
        type: ClassPassiveType.criticalBonus,
        value: 0.05,
        description: '크리티컬 +5%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  // ==========================================================================
  // 지혜 계열 (WIS 기반)
  // ==========================================================================

  /// Exception Handler: WIS + INT (스탯 합계: +3)
  static const exceptionHandler = ClassTraits(
    classId: 'exception_handler',
    name: 'Exception Handler',
    statModifiers: {StatType.wis: 2, StatType.intelligence: 1},
    startingSkills: ['heal'],
    classSkills: ['heal', 'try_catch', 'finally_heal'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.healingBonus,
        value: 0.15,
        description: '회복력 +15%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// Null Checker: WIS + INT (스탯 합계: +3)
  static const nullChecker = ClassTraits(
    classId: 'null_checker',
    name: 'Null Checker',
    statModifiers: {StatType.wis: 2, StatType.intelligence: 1},
    startingSkills: ['heal'],
    classSkills: ['heal', 'null_guard', 'safe_call'],
    passives: [
      ClassPassive(
        type: ClassPassiveType.healingBonus,
        value: 0.10,
        description: '회복력 +10%',
      ),
      ClassPassive(
        type: ClassPassiveType.defenseBonus,
        value: 0.05,
        description: '방어력 +5%',
      ),
    ],
    restriction: EquipmentRestriction(armorWeight: ArmorWeight.light),
  );

  /// 모든 클래스 목록 (18개)
  static const List<ClassTraits> all = [
    // 전사 계열
    bugHunter,
    overflowWarrior,
    stackCrusher,
    assertionKnight,
    // 탱커 계열
    debuggerPaladin,
    loopBreaker,
    garbageCollector,
    // 마법사 계열
    compilerMage,
    recursionMaster,
    memoryLeaker,
    typeCaster,
    devOpsShaman,
    // 민첩 계열
    refactorMonk,
    pointerAssassin,
    callbackSamurai,
    testerJester,
    // 지혜 계열
    exceptionHandler,
    nullChecker,
  ];

  /// ID로 클래스 찾기
  static ClassTraits? findById(String classId) {
    for (final klass in all) {
      if (klass.classId == classId) return klass;
    }
    return null;
  }

  /// 이름으로 클래스 찾기
  static ClassTraits? findByName(String name) {
    for (final klass in all) {
      if (klass.name == name) return klass;
    }
    return null;
  }
}
