import {
  buildOpponentSlotDebuffChoices,
  buildSelfSlotUpgradeChoices,
} from '../../../combat/roguelikeUpgrades'
import type { Spell } from '../../../game'
import { type Iwt2HealerAbility } from './healerAbilities'

export type Iwt2RoguelikeVariant = 'pve' | 'pvp'
export type Iwt2RoguelikeContentType = 'dungeon' | 'raid' | 'stadium'
export type Iwt2RoguelikeSlot = '1' | '2' | '3' | '4' | '5'

export type Iwt2RoguelikeSelfBuffId =
  | 'revive-party-members'
  | `slot${Iwt2RoguelikeSlot}-extra-target`
  | `slot${Iwt2RoguelikeSlot}-cost-down`
  | `slot${Iwt2RoguelikeSlot}-cooldown-down`

export type Iwt2RoguelikeOpponentDebuffId =
  | `opp-slot${Iwt2RoguelikeSlot}-cost-up`
  | `opp-slot${Iwt2RoguelikeSlot}-cooldown-up`

export type Iwt2RoguelikeChoice<T extends string> = {
  id: T
  name: string
  description: string
}

export const IWT2_ROGUELIKE_SLOTS: readonly Iwt2RoguelikeSlot[] = ['1', '2', '3', '4', '5']

export const IWT2_REVIVE_PARTY_CHOICE: Iwt2RoguelikeChoice<Iwt2RoguelikeSelfBuffId> = {
  id: 'revive-party-members',
  name: 'Revive Party Members',
  description: 'Revive fallen party members before the next IWT2 arena.',
}

export function iwt2AbilityToSpell(ability: Iwt2HealerAbility): Spell {
  return {
    id: ability.id,
    key: String(ability.slot),
    name: ability.name,
    description: ability.name,
    cost: ability.manaCost,
    cooldown: ability.cooldownSeconds,
    power: ability.power,
    glyph: ability.icon,
    kind: ability.kind,
    effectType: ability.effectType,
  }
}

export function buildIwt2SelfBuffChoices(abilities: Iwt2HealerAbility[]) {
  return buildSelfSlotUpgradeChoices<Iwt2RoguelikeSelfBuffId>({
    slots: IWT2_ROGUELIKE_SLOTS,
    spells: abilities.map(iwt2AbilityToSpell),
    labelMode: 'ability',
  })
}

export function buildIwt2OpponentDebuffChoices(abilities: Iwt2HealerAbility[]) {
  return buildOpponentSlotDebuffChoices<Iwt2RoguelikeOpponentDebuffId>({
    slots: IWT2_ROGUELIKE_SLOTS,
    spells: abilities.map(iwt2AbilityToSpell),
    labelMode: 'ability',
  })
}
