import { IWT2_BALANCE_OVERRIDES } from './balanceOverrides'

export type Iwt2BossId = 'bulldrome' | 'yian-kut-ku' | 'great-jaggi' | 'khezu'

export type Iwt2BalanceOverrides = {
  bosses?: Partial<Record<Iwt2BossId, Partial<Pick<Iwt2BossMetadata, 'maxHealth' | 'birdHealth'>>>>
}

export type Iwt2BossMetadata = {
  id: Iwt2BossId
  name: string
  icon: string
  color: string
  accentColor: string
  maxHealth: number
  radius: number
  moveSpeed: number
  meleeRange: number
  meleeDamage: number
  meleeCooldown: number
  chargeCooldown: number
  chargeWindup: number
  chargeSpeed: number
  chargeDamage: number
  chargeStunSeconds: number
  chargeLength: number
  chargeOvershoot: number
  chargeWidth: number
  slamWindup: number
  slamRadius: number
  slamDamage: number
  slamStunSeconds: number
  fireballCooldown?: number
  fireballWindup?: number
  fireballSpeed?: number
  fireballDamage?: number
  fireballRadius?: number
  firePuddleRadius?: number
  firePuddleDamage?: number
  firePuddleSeconds?: number
  birdWaveThresholds?: number[]
  birdFlightCooldown?: number
  birdFlightWindup?: number
  birdFlightSpeed?: number
  birdHealth?: number
  birdRadius?: number
  birdContactDamage?: number
  birdStunSeconds?: number
  packHowlCooldown?: number
  packHowlWindup?: number
  packLaneDamage?: number
  packLaneStunSeconds?: number
  packLaneWidth?: number
  packLaneCount?: number
  thunderRingCooldown?: number
  thunderRingWindup?: number
  thunderRingInnerRadius?: number
  thunderRingOuterRadius?: number
  thunderRingDamage?: number
  thunderRingStunSeconds?: number
  lightningStrikeCooldown?: number
  lightningStrikeWindup?: number
  lightningStrikeRadius?: number
  lightningStrikeDamage?: number
  lightningStrikeStunSeconds?: number
  lightningStrikeCount?: number
}

const DEFAULT_BULLDROME_BOSS_METADATA: Iwt2BossMetadata = {
  id: 'bulldrome',
  name: 'Bulldrome',
  icon: 'B',
  color: '#8f5a3c',
  accentColor: '#e6b17f',
  maxHealth: 950,
  radius: 31,
  moveSpeed: 128,
  meleeRange: 58,
  meleeDamage: 9,
  meleeCooldown: 1.05,
  chargeCooldown: 4.75,
  chargeWindup: 0.55,
  chargeSpeed: 510,
  chargeDamage: 32,
  chargeStunSeconds: 0.75,
  chargeLength: 560,
  chargeOvershoot: 120,
  chargeWidth: 62,
  slamWindup: 0.45,
  slamRadius: 104,
  slamDamage: 24,
  slamStunSeconds: 0.75,
}

const DEFAULT_YIAN_KUT_KU_BOSS_METADATA: Iwt2BossMetadata = {
  id: 'yian-kut-ku',
  name: 'Yian Kut Ku',
  icon: 'Y',
  color: '#d66a35',
  accentColor: '#ffd166',
  maxHealth: 400,
  radius: 29,
  moveSpeed: 118,
  meleeRange: 56,
  meleeDamage: 8,
  meleeCooldown: 1,
  chargeCooldown: 0,
  chargeWindup: 0,
  chargeSpeed: 0,
  chargeDamage: 0,
  chargeStunSeconds: 0,
  chargeLength: 0,
  chargeOvershoot: 0,
  chargeWidth: 0,
  slamWindup: 0,
  slamRadius: 0,
  slamDamage: 0,
  slamStunSeconds: 0,
  fireballCooldown: 3.6,
  fireballWindup: 0.55,
  fireballSpeed: 285,
  fireballDamage: 12,
  fireballRadius: 9,
  firePuddleRadius: 42,
  firePuddleDamage: 7,
  firePuddleSeconds: 8,
  birdWaveThresholds: [0.9, 0.4],
  birdFlightCooldown: 10,
  birdFlightWindup: 0.85,
  birdFlightSpeed: 360,
  birdHealth: 58,
  birdRadius: 16,
  birdContactDamage: 10,
  birdStunSeconds: 0.75,
}

const DEFAULT_GREAT_JAGGI_BOSS_METADATA: Iwt2BossMetadata = {
  id: 'great-jaggi',
  name: 'Great Jaggi',
  icon: 'J',
  color: '#3f8f73',
  accentColor: '#b8f0aa',
  maxHealth: 620,
  radius: 27,
  moveSpeed: 146,
  meleeRange: 52,
  meleeDamage: 7,
  meleeCooldown: 0.82,
  chargeCooldown: 0,
  chargeWindup: 0,
  chargeSpeed: 0,
  chargeDamage: 0,
  chargeStunSeconds: 0,
  chargeLength: 0,
  chargeOvershoot: 0,
  chargeWidth: 0,
  slamWindup: 0,
  slamRadius: 0,
  slamDamage: 0,
  slamStunSeconds: 0,
  packHowlCooldown: 5.8,
  packHowlWindup: 0.95,
  packLaneDamage: 15,
  packLaneStunSeconds: 0.45,
  packLaneWidth: 24,
  packLaneCount: 3,
}

const DEFAULT_KHEZU_BOSS_METADATA: Iwt2BossMetadata = {
  id: 'khezu',
  name: 'Khezu',
  icon: 'K',
  color: '#d8d7c9',
  accentColor: '#77d9ff',
  maxHealth: 760,
  radius: 30,
  moveSpeed: 92,
  meleeRange: 58,
  meleeDamage: 10,
  meleeCooldown: 1.15,
  chargeCooldown: 0,
  chargeWindup: 0,
  chargeSpeed: 0,
  chargeDamage: 0,
  chargeStunSeconds: 0,
  chargeLength: 0,
  chargeOvershoot: 0,
  chargeWidth: 0,
  slamWindup: 0,
  slamRadius: 0,
  slamDamage: 0,
  slamStunSeconds: 0,
  thunderRingCooldown: 7.2,
  thunderRingWindup: 0.9,
  thunderRingInnerRadius: 70,
  thunderRingOuterRadius: 172,
  thunderRingDamage: 22,
  thunderRingStunSeconds: 0.7,
  lightningStrikeCooldown: 4.2,
  lightningStrikeWindup: 0.78,
  lightningStrikeRadius: 46,
  lightningStrikeDamage: 17,
  lightningStrikeStunSeconds: 0.55,
  lightningStrikeCount: 2,
}

function applyBossOverrides(metadata: Iwt2BossMetadata): Iwt2BossMetadata {
  const override = IWT2_BALANCE_OVERRIDES.bosses?.[metadata.id]
  if (!override) return metadata
  return {
    ...metadata,
    ...override,
  }
}

export const BULLDROME_BOSS_METADATA: Iwt2BossMetadata = applyBossOverrides(DEFAULT_BULLDROME_BOSS_METADATA)
export const YIAN_KUT_KU_BOSS_METADATA: Iwt2BossMetadata = applyBossOverrides(DEFAULT_YIAN_KUT_KU_BOSS_METADATA)
export const GREAT_JAGGI_BOSS_METADATA: Iwt2BossMetadata = applyBossOverrides(DEFAULT_GREAT_JAGGI_BOSS_METADATA)
export const KHEZU_BOSS_METADATA: Iwt2BossMetadata = applyBossOverrides(DEFAULT_KHEZU_BOSS_METADATA)

export const IWT2_BOSS_METADATA: Record<Iwt2BossId, Iwt2BossMetadata> = {
  bulldrome: BULLDROME_BOSS_METADATA,
  'yian-kut-ku': YIAN_KUT_KU_BOSS_METADATA,
  'great-jaggi': GREAT_JAGGI_BOSS_METADATA,
  khezu: KHEZU_BOSS_METADATA,
}
