import type { LootEntry, MobTemplate } from './claudeCraftTypes'

function mob(
  id: string,
  name: string,
  level: number,
  family: MobTemplate['family'],
  loot: LootEntry[],
  options: Partial<Pick<MobTemplate, 'boss' | 'elite' | 'scale' | 'color' | 'aggroRadius'>> = {},
): MobTemplate {
  return {
    aggroRadius: options.aggroRadius ?? (options.boss ? 16 : 12),
    armorPerLevel: 18,
    attackSpeed: 2.2,
    color: options.color ?? 0x839192,
    dmgBase: options.boss ? 12 : 8,
    dmgPerLevel: options.boss ? 2.8 : 2.3,
    elite: options.elite ?? true,
    family,
    hpBase: options.boss ? 230 : 54,
    hpPerLevel: options.boss ? 34 : 20,
    id,
    loot,
    maxLevel: level,
    minLevel: level,
    moveSpeed: 7,
    name,
    scale: options.scale ?? (options.boss ? 1.35 : 1.05),
    boss: options.boss,
  }
}

export const CLAUDECRAFT_DUNGEON_MOBS: Record<string, MobTemplate> = {
  crypt_shambler: mob('crypt_shambler', 'Crypt Shambler', 8, 'undead', [
    { copper: 90, chance: 1 },
    { itemId: 'bone_fragments', chance: 0.8 },
  ]),
  hollow_acolyte: mob('hollow_acolyte', 'Hollow Acolyte', 8, 'undead', [
    { copper: 110, chance: 1 },
    { itemId: 'linen_scrap', chance: 0.6 },
  ]),
  bonechill_widow: mob('bonechill_widow', 'Bonechill Widow', 9, 'spider', [
    { copper: 120, chance: 1 },
    { itemId: 'spider_leg', chance: 0.7 },
  ]),
  sexton_marrow: mob('sexton_marrow', 'Sexton Marrow', 9, 'undead', [
    { copper: 400, chance: 1 },
    { itemId: 'quilted_trousers', chance: 0.4 },
    { itemId: 'oiled_boots', chance: 0.4 },
  ]),
  morthen: mob('morthen', 'Morthen the Gravecaller', 10, 'undead', [
    { copper: 2500, chance: 1 },
    { itemId: 'cryptbone_greaves', chance: 0.34, rollGroup: 'morthen_guaranteed_uncommon' },
    { itemId: 'quilted_trousers', chance: 0.33, rollGroup: 'morthen_guaranteed_uncommon' },
    { itemId: 'oiled_boots', chance: 0.33, rollGroup: 'morthen_guaranteed_uncommon' },
    { itemId: 'greyjaw_hide_boots', chance: 0.25, rollGroup: 'morthen_bonus' },
    { itemId: 'cryptbone_helm', chance: 0.18, rollGroup: 'morthen_bonus' },
    { itemId: 'cryptbone_pauldrons', chance: 0.18, rollGroup: 'morthen_bonus' },
  ], { boss: true, color: 0x4a235a }),

  bastion_revenant: mob('bastion_revenant', 'Bastion Revenant', 13, 'undead', [
    { copper: 150, chance: 1 },
    { itemId: 'bone_fragments', chance: 0.7 },
    { itemId: 'mistveil_cord', chance: 0.06, rollGroup: 'revenant_bonus' },
  ]),
  tidebound_acolyte: mob('tidebound_acolyte', 'Tidebound Acolyte', 13, 'humanoid', [
    { copper: 170, chance: 1 },
    { itemId: 'linen_scrap', chance: 0.5 },
    { itemId: 'mistveil_grips', chance: 0.06, rollGroup: 'acolyte_bonus' },
  ]),
  knight_commander_olen: mob('knight_commander_olen', 'Knight-Commander Olen', 13, 'undead', [
    { copper: 800, chance: 1 },
    { itemId: 'trollhide_leggings', chance: 0.5, rollGroup: 'olen_guaranteed_uncommon' },
    { itemId: 'marshstrider_boots', chance: 0.5, rollGroup: 'olen_guaranteed_uncommon' },
    { itemId: 'fenmist_robe', chance: 0.25, rollGroup: 'olen_bonus' },
    { itemId: 'tideguard_greaves', chance: 0.1, rollGroup: 'olen_bonus' },
    { itemId: 'tideguard_sabatons', chance: 0.1, rollGroup: 'olen_bonus' },
    { itemId: 'eelscale_leggings', chance: 0.1, rollGroup: 'olen_bonus' },
  ], { scale: 1.2 }),
  vael_the_mistcaller: mob('vael_the_mistcaller', 'Vael the Mistcaller', 13, 'humanoid', [
    { copper: 5000, chance: 1 },
    { itemId: 'trollhide_leggings', chance: 0.34, rollGroup: 'vael_guaranteed_uncommon' },
    { itemId: 'marshstrider_boots', chance: 0.33, rollGroup: 'vael_guaranteed_uncommon' },
    { itemId: 'fenmist_robe', chance: 0.33, rollGroup: 'vael_guaranteed_uncommon' },
    { itemId: 'deepfen_pearl', chance: 1 },
    { itemId: 'eelskin_tunic', chance: 0.2, rollGroup: 'vael_bonus' },
    { itemId: 'tidescale_vest', chance: 0.1, rollGroup: 'vael_bonus' },
    { itemId: 'drowned_prayer_leggings', chance: 0.1, rollGroup: 'vael_bonus' },
    { itemId: 'drowned_prayer_sandals', chance: 0.1, rollGroup: 'vael_bonus' },
    { itemId: 'eelscale_treads', chance: 0.1, rollGroup: 'vael_bonus' },
    { itemId: 'mistveil_cord', chance: 0.12, rollGroup: 'vael_bonus' },
    { itemId: 'mistveil_grips', chance: 0.12, rollGroup: 'vael_bonus' },
  ], { boss: true, color: 0x48c9b0 }),

  sanctum_boneguard: mob('sanctum_boneguard', 'Sanctum Boneguard', 19, 'undead', [
    { copper: 300, chance: 1 },
    { itemId: 'bone_fragments', chance: 0.6 },
    { itemId: 'boundstone_helm', chance: 0.04, rollGroup: 'boneguard_bonus' },
    { itemId: 'boundstone_girdle', chance: 0.04, rollGroup: 'boneguard_bonus' },
  ]),
  sanctum_drakonid: mob('sanctum_drakonid', 'Sanctum Drakonid', 20, 'dragonkin', [
    { copper: 350, chance: 1 },
    { itemId: 'cracked_wyrm_scale', chance: 0.5 },
    { itemId: 'gravewyrm_mantle', chance: 0.05, rollGroup: 'drakonid_bonus' },
    { itemId: 'gravewyrm_gauntlets', chance: 0.05, rollGroup: 'drakonid_bonus' },
  ]),
  korgath_the_bound: mob('korgath_the_bound', 'Korgath the Bound', 20, 'ogre', [
    { copper: 5000, chance: 1 },
    { itemId: 'boneplate_vest', chance: 0.34, rollGroup: 'korgath_guaranteed_uncommon' },
    { itemId: 'revenant_silk_robe', chance: 0.33, rollGroup: 'korgath_guaranteed_uncommon' },
    { itemId: 'nightwalk_jerkin', chance: 0.33, rollGroup: 'korgath_guaranteed_uncommon' },
    { itemId: 'zealotsbane_blade', chance: 0.2, rollGroup: 'korgath_bonus' },
    { itemId: 'korgaths_chainwraps', chance: 0.1, rollGroup: 'korgath_bonus' },
    { itemId: 'staff_of_velkhar', chance: 0.1, rollGroup: 'korgath_bonus' },
    { itemId: 'shadowmeld_tunic', chance: 0.1, rollGroup: 'korgath_bonus' },
    { itemId: 'wyrmcult_grand_robe', chance: 0.1, rollGroup: 'korgath_bonus' },
    { itemId: 'gravewyrm_sabatons', chance: 0.1, rollGroup: 'korgath_bonus' },
    { itemId: 'wyrmcult_soulsteps', chance: 0.1, rollGroup: 'korgath_bonus' },
    { itemId: 'wyrmshadow_treads', chance: 0.05, rollGroup: 'korgath_bonus' },
    { itemId: 'boundstone_helm', chance: 0.08, rollGroup: 'korgath_bonus' },
    { itemId: 'gravewyrm_mantle', chance: 0.08, rollGroup: 'korgath_bonus' },
  ], { scale: 1.5 }),
  grand_necromancer_velkhar: mob('grand_necromancer_velkhar', 'Grand Necromancer Velkhar', 20, 'humanoid', [
    { copper: 5000, chance: 1 },
    { itemId: 'boneplate_vest', chance: 0.34, rollGroup: 'velkhar_guaranteed_uncommon' },
    { itemId: 'revenant_silk_robe', chance: 0.33, rollGroup: 'velkhar_guaranteed_uncommon' },
    { itemId: 'nightwalk_jerkin', chance: 0.33, rollGroup: 'velkhar_guaranteed_uncommon' },
    { itemId: 'emberwood_staff', chance: 0.2, rollGroup: 'velkhar_bonus' },
    { itemId: 'boneguard_breastplate', chance: 0.1, rollGroup: 'velkhar_bonus' },
    { itemId: 'shadowmeld_tunic', chance: 0.1, rollGroup: 'velkhar_bonus' },
    { itemId: 'staff_of_velkhar', chance: 0.1, rollGroup: 'velkhar_bonus' },
    { itemId: 'gravewyrm_stalkers_treads', chance: 0.1, rollGroup: 'velkhar_bonus' },
    { itemId: 'deathlord_legguards', chance: 0.05, rollGroup: 'velkhar_bonus' },
    { itemId: 'necromancers_soulsteps', chance: 0.05, rollGroup: 'velkhar_bonus' },
    { itemId: 'wyrmshadow_legguards', chance: 0.05, rollGroup: 'velkhar_bonus' },
  ], { scale: 1.25 }),
  korzul_the_gravewyrm: mob('korzul_the_gravewyrm', 'Korzul the Gravewyrm', 20, 'dragonkin', [
    { copper: 50000, chance: 1 },
    { itemId: 'boneplate_vest', chance: 0.34, rollGroup: 'korzul_guaranteed_uncommon' },
    { itemId: 'revenant_silk_robe', chance: 0.33, rollGroup: 'korzul_guaranteed_uncommon' },
    { itemId: 'nightwalk_jerkin', chance: 0.33, rollGroup: 'korzul_guaranteed_uncommon' },
    { itemId: 'cultist_flayer', chance: 0.1, rollGroup: 'korzul_bonus' },
    { itemId: 'wyrmfang_greatblade', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'staff_of_the_gravewyrm', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'fang_of_korzul', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'deathlord_warplate', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'necromancers_starshroud', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'wyrmshadow_harness', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'boundstone_girdle', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'gravewyrm_gauntlets', chance: 0.05, rollGroup: 'korzul_bonus' },
    { itemId: 'deathlords_dread_visage', chance: 0.04, rollGroup: 'korzul_bonus' },
    { itemId: 'necromancers_soulspire_mantle', chance: 0.04, rollGroup: 'korzul_bonus' },
    { itemId: 'wyrmshadow_talongrips', chance: 0.04, rollGroup: 'korzul_bonus' },
  ], { boss: true, scale: 1.8, color: 0x3d5c45 }),
  nythraxis_scourge_of_thornpeak: mob('nythraxis_scourge_of_thornpeak', 'Nythraxis, Scourge of Thornpeak', 20, 'undead', [
    { copper: 150000, chance: 1 },
    { itemId: 'deathless_heartwood', chance: 0.03, rollGroup: 'nythraxis_drop_1' },
    { itemId: 'crownforged_dreadhelm', chance: 0.17, rollGroup: 'nythraxis_drop_1' },
    { itemId: 'nighttalon_crown', chance: 0.16, rollGroup: 'nythraxis_drop_1' },
    { itemId: 'soulflame_cowl', chance: 0.16, rollGroup: 'nythraxis_drop_1' },
    { itemId: 'stormcallers_crown', chance: 0.16, rollGroup: 'nythraxis_drop_1' },
    { itemId: 'nighttalon_shoulderguards', chance: 0.16, rollGroup: 'nythraxis_drop_1' },
    { itemId: 'soulflame_mantle', chance: 0.16, rollGroup: 'nythraxis_drop_1' },
    { itemId: 'kingsbane_last_oath', chance: 0.03, rollGroup: 'nythraxis_drop_2' },
    { itemId: 'crownforged_warspaulders', chance: 0.17, rollGroup: 'nythraxis_drop_2' },
    { itemId: 'nighttalon_shoulderguards', chance: 0.16, rollGroup: 'nythraxis_drop_2' },
    { itemId: 'soulflame_mantle', chance: 0.16, rollGroup: 'nythraxis_drop_2' },
    { itemId: 'stormcallers_spaulders', chance: 0.16, rollGroup: 'nythraxis_drop_2' },
  ], { boss: true, scale: 3.1, color: 0x221b2d }),
}

export const ACTION_DUNGEON_LOOT_MOBS: Record<string, string[]> = {
  bulldrome: ['crypt_shambler', 'sexton_marrow'],
  'yian-kut-ku': ['bonechill_widow', 'morthen'],
  'cyber-dragon': ['sanctum_drakonid', 'korgath_the_bound'],
  'hollow-crypt': ['crypt_shambler', 'hollow_acolyte', 'bonechill_widow', 'sexton_marrow', 'morthen'],
  'sunken-bastion': ['bastion_revenant', 'tidebound_acolyte', 'knight_commander_olen', 'vael_the_mistcaller'],
  'gravewyrm-sanctum': ['sanctum_boneguard', 'sanctum_drakonid', 'korgath_the_bound', 'grand_necromancer_velkhar', 'korzul_the_gravewyrm'],
  'abandoned-crypt': ['crypt_shambler', 'hollow_acolyte', 'morthen'],
  'nythraxis-raid': ['nythraxis_scourge_of_thornpeak'],
}
