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

/// 종족 데이터 정의 (race data)
///
/// 21가지 종족 - 모든 종족의 스탯 합계 = 0 (균형)
/// 패시브는 각 종족의 고유한 플레이스타일을 정의
class RaceData {
  RaceData._();

  // ==========================================================================
  // HP/균형형 종족
  // ==========================================================================

  /// Byte Human: 균형형 (스탯 합계: 0)
  /// 특화 없이 경험치로 보상
  static const byteHuman = RaceTraits(
    raceId: 'byte_human',
    name: 'Byte Human',
    statModifiers: {},
    passives: [
      PassiveAbility(
        type: PassiveType.expBonus,
        value: 0.05,
        description: '경험치 +5%',
      ),
    ],
    expMultiplier: 1.05,
  );

  /// Kernel Giant: 탱커형 (스탯 합계: 0)
  /// STR/CON +2, DEX/INT -2
  static const kernelGiant = RaceTraits(
    raceId: 'kernel_giant',
    name: 'Kernel Giant',
    statModifiers: {
      StatType.str: 2,
      StatType.con: 2,
      StatType.dex: -2,
      StatType.intelligence: -2,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.hpBonus,
        value: 0.10,
        description: 'HP +10%',
      ),
    ],
  );

  // ==========================================================================
  // 지혜/마법 종족 (WIS 기반)
  // ==========================================================================

  /// Null Elf: 마법형 (스탯 합계: 0)
  /// WIS/INT +2, STR/CON -2
  static const nullElf = RaceTraits(
    raceId: 'null_elf',
    name: 'Null Elf',
    statModifiers: {
      StatType.wis: 2,
      StatType.intelligence: 1,
      StatType.str: -2,
      StatType.con: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.magicDamageBonus,
        value: 0.08,
        description: '마법 데미지 +8%',
      ),
    ],
  );

  /// Recursive Sylvan: 순수 마법형 (스탯 합계: 0)
  /// WIS/INT +2, STR -2, DEX -1, CHA +1
  static const recursiveSylvan = RaceTraits(
    raceId: 'recursive_sylvan',
    name: 'Recursive Sylvan',
    statModifiers: {
      StatType.wis: 2,
      StatType.intelligence: 2,
      StatType.str: -2,
      StatType.dex: -1,
      StatType.con: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.mpBonus,
        value: 0.10,
        description: 'MP +10%',
      ),
    ],
  );

  /// Callback Seraph: 지원형 (스탯 합계: 0)
  /// WIS +2, CHA +1, STR -1, DEX -1, CON -1
  static const callbackSeraph = RaceTraits(
    raceId: 'callback_seraph',
    name: 'Callback Seraph',
    statModifiers: {
      StatType.wis: 2,
      StatType.cha: 1,
      StatType.str: -1,
      StatType.dex: -1,
      StatType.con: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.expBonus,
        value: 0.03,
        description: '경험치 +3%',
      ),
    ],
    expMultiplier: 1.03,
  );

  // ==========================================================================
  // 체력/방어 종족 (CON 기반)
  // ==========================================================================

  /// Buffer Dwarf: 방어형 (스탯 합계: 0)
  /// CON +2, STR +1, DEX -2, CHA -1
  static const bufferDwarf = RaceTraits(
    raceId: 'buffer_dwarf',
    name: 'Buffer Dwarf',
    statModifiers: {
      StatType.con: 2,
      StatType.str: 1,
      StatType.dex: -2,
      StatType.cha: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.defenseBonus,
        value: 0.08,
        description: '방어력 +8%',
      ),
    ],
  );

  /// Coredump Undead: 생존형 (스탯 합계: 0)
  /// CON +2, STR +1, CHA -2, DEX -1
  static const coredumpUndead = RaceTraits(
    raceId: 'coredump_undead',
    name: 'Coredump Undead',
    statModifiers: {
      StatType.con: 2,
      StatType.str: 1,
      StatType.cha: -2,
      StatType.dex: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.defenseBonus,
        value: 0.10,
        description: '방어력 +10%',
      ),
    ],
  );

  // ==========================================================================
  // 민첩/크리티컬 종족 (DEX 기반)
  // ==========================================================================

  /// Bit Halfling: 민첩형 (스탯 합계: 0)
  /// DEX +2, CHA +1, STR -2, CON -1
  static const bitHalfling = RaceTraits(
    raceId: 'bit_halfling',
    name: 'Bit Halfling',
    statModifiers: {
      StatType.dex: 2,
      StatType.cha: 1,
      StatType.str: -2,
      StatType.con: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.criticalBonus,
        value: 0.03,
        description: '크리티컬 +3%',
      ),
    ],
  );

  /// Cache Imp: 속도형 (스탯 합계: 0)
  /// DEX +2, INT +1, CON -2, WIS -1
  static const cacheImp = RaceTraits(
    raceId: 'cache_imp',
    name: 'Cache Imp',
    statModifiers: {
      StatType.dex: 2,
      StatType.intelligence: 1,
      StatType.con: -2,
      StatType.wis: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.criticalBonus,
        value: 0.02,
        description: '크리티컬 +2%',
      ),
    ],
  );

  /// Iterator Shade: 암살형 (스탯 합계: 0)
  /// DEX +3, STR +1, CON -2, WIS -1, CHA -1
  static const iteratorShade = RaceTraits(
    raceId: 'iterator_shade',
    name: 'Iterator Shade',
    statModifiers: {
      StatType.dex: 3,
      StatType.str: 1,
      StatType.con: -2,
      StatType.wis: -1,
      StatType.cha: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.criticalBonus,
        value: 0.04,
        description: '크리티컬 +4%',
      ),
    ],
  );

  // ==========================================================================
  // 힘/물리 종족 (STR 기반)
  // ==========================================================================

  /// Array Orc: 공격형 (스탯 합계: 0)
  /// STR +2, CON +1, INT -2, WIS -1
  static const arrayOrc = RaceTraits(
    raceId: 'array_orc',
    name: 'Array Orc',
    statModifiers: {
      StatType.str: 2,
      StatType.con: 1,
      StatType.intelligence: -2,
      StatType.wis: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.hpBonus,
        value: 0.05,
        description: 'HP +5%',
      ),
    ],
  );

  /// Flag Golem: 전사형 (스탯 합계: 0)
  /// STR +2, CHA +1, INT -2, WIS -1
  static const flagGolem = RaceTraits(
    raceId: 'flag_golem',
    name: 'Flag Golem',
    statModifiers: {
      StatType.str: 2,
      StatType.cha: 1,
      StatType.intelligence: -2,
      StatType.wis: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.defenseBonus,
        value: 0.05,
        description: '방어력 +5%',
      ),
    ],
  );

  /// Protocol Valkyrie: 수호자형 (스탯 합계: 0)
  /// STR +2, CON +1, CHA +1, DEX -2, INT -2
  static const protocolValkyrie = RaceTraits(
    raceId: 'protocol_valkyrie',
    name: 'Protocol Valkyrie',
    statModifiers: {
      StatType.str: 2,
      StatType.con: 1,
      StatType.cha: 1,
      StatType.dex: -2,
      StatType.intelligence: -2,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.defenseBonus,
        value: 0.06,
        description: '방어력 +6%',
      ),
    ],
  );

  // ==========================================================================
  // 복합 스탯 종족
  // ==========================================================================

  /// Stack Goblin: 기동형 (스탯 합계: 0)
  /// DEX +2, CON +1, STR -1, CHA -2
  static const stackGoblin = RaceTraits(
    raceId: 'stack_goblin',
    name: 'Stack Goblin',
    statModifiers: {
      StatType.dex: 2,
      StatType.con: 1,
      StatType.str: -1,
      StatType.cha: -2,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.criticalBonus,
        value: 0.02,
        description: '크리티컬 +2%',
      ),
    ],
  );

  /// Heap Troll: 중장갑형 (스탯 합계: 0)
  /// CON +2, STR +2, INT -2, DEX -2
  static const heapTroll = RaceTraits(
    raceId: 'heap_troll',
    name: 'Heap Troll',
    statModifiers: {
      StatType.con: 2,
      StatType.str: 2,
      StatType.intelligence: -2,
      StatType.dex: -2,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.hpBonus,
        value: 0.12,
        description: 'HP +12%',
      ),
    ],
  );

  /// Index Feline: 정찰형 (스탯 합계: 0)
  /// DEX +2, CON +1, INT -1, CHA -2
  static const indexFeline = RaceTraits(
    raceId: 'index_feline',
    name: 'Index Feline',
    statModifiers: {
      StatType.dex: 2,
      StatType.con: 1,
      StatType.intelligence: -1,
      StatType.cha: -2,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.criticalBonus,
        value: 0.03,
        description: '크리티컬 +3%',
      ),
    ],
  );

  // ==========================================================================
  // MP/주문 종족 (INT/MP 기반)
  // ==========================================================================

  /// Pointer Fairy: MP 특화형 (스탯 합계: 0)
  /// WIS +2, INT +1, STR -2, CON -1
  static const pointerFairy = RaceTraits(
    raceId: 'pointer_fairy',
    name: 'Pointer Fairy',
    statModifiers: {
      StatType.wis: 2,
      StatType.intelligence: 1,
      StatType.str: -2,
      StatType.con: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.mpBonus,
        value: 0.12,
        description: 'MP +12%',
      ),
    ],
  );

  /// Register Gnome: 지능형 (스탯 합계: 0)
  /// INT +2, DEX +1, STR -2, CON -1
  static const registerGnome = RaceTraits(
    raceId: 'register_gnome',
    name: 'Register Gnome',
    statModifiers: {
      StatType.intelligence: 2,
      StatType.dex: 1,
      StatType.str: -2,
      StatType.con: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.magicDamageBonus,
        value: 0.05,
        description: '마법 데미지 +5%',
      ),
    ],
  );

  /// Thread Spirit: 영체형 (스탯 합계: 0)
  /// INT +1, WIS +1, CON -2
  static const threadSpirit = RaceTraits(
    raceId: 'thread_spirit',
    name: 'Thread Spirit',
    statModifiers: {
      StatType.intelligence: 1,
      StatType.wis: 1,
      StatType.con: -2,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.mpBonus,
        value: 0.15,
        description: 'MP +15%',
      ),
    ],
  );

  /// Loop Djinn: 순환 마법형 (스탯 합계: 0)
  /// INT +2, WIS +1, STR -1, CON -1, DEX -1
  static const loopDjinn = RaceTraits(
    raceId: 'loop_djinn',
    name: 'Loop Djinn',
    statModifiers: {
      StatType.intelligence: 2,
      StatType.wis: 1,
      StatType.str: -1,
      StatType.con: -1,
      StatType.dex: -1,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.mpBonus,
        value: 0.08,
        description: 'MP +8%',
      ),
      PassiveAbility(
        type: PassiveType.magicDamageBonus,
        value: 0.04,
        description: '마법 데미지 +4%',
      ),
    ],
  );

  /// Lambda Dryad: 자연 마법형 (스탯 합계: 0)
  /// INT +2, WIS +2, STR -2, CON -2
  static const lambdaDryad = RaceTraits(
    raceId: 'lambda_dryad',
    name: 'Lambda Dryad',
    statModifiers: {
      StatType.intelligence: 2,
      StatType.wis: 2,
      StatType.str: -2,
      StatType.con: -2,
    },
    passives: [
      PassiveAbility(
        type: PassiveType.magicDamageBonus,
        value: 0.06,
        description: '마법 데미지 +6%',
      ),
      PassiveAbility(
        type: PassiveType.mpBonus,
        value: 0.06,
        description: 'MP +6%',
      ),
    ],
  );

  /// 모든 종족 목록 (21개)
  static const List<RaceTraits> all = [
    // 균형형
    byteHuman,
    kernelGiant,
    // 지혜형
    nullElf,
    recursiveSylvan,
    callbackSeraph,
    // 체력형
    bufferDwarf,
    coredumpUndead,
    // 민첩형
    bitHalfling,
    cacheImp,
    iteratorShade,
    // 힘형
    arrayOrc,
    flagGolem,
    protocolValkyrie,
    // 복합형
    stackGoblin,
    heapTroll,
    indexFeline,
    // 마법형
    pointerFairy,
    registerGnome,
    threadSpirit,
    loopDjinn,
    lambdaDryad,
  ];

  /// ID로 종족 찾기
  static RaceTraits? findById(String raceId) {
    for (final race in all) {
      if (race.raceId == raceId) return race;
    }
    return null;
  }

  /// 이름으로 종족 찾기
  static RaceTraits? findByName(String name) {
    for (final race in all) {
      if (race.name == name) return race;
    }
    return null;
  }
}
