-- PaladinHolyPower - logic/hp_sources.lua
-- Clean: generators and *baseline* spender costs only.
-- No DP/EP logic here; hp_log.lua handles procs + verification.

local PHP = _G.PaladinHolyPower
if not PHP then return end

-- -------- Helpers --------
local function IsTalent(id)
  if _G.IsPlayerSpell then return _G.IsPlayerSpell(id) end
  return false
end

local function TargetHPpct()
  if _G.UnitHealth and _G.UnitHealthMax then
    local m=_G.UnitHealthMax("target")
    if m and m>0 then return (100.0 * _G.UnitHealth("target") / m) end
  end
  return nil
end

-- -------- IDs (Generators) --------
local TEMPLAR_STRIKES    = 407480
local TEMPLAR_SLASH      = 406647
local CRUSADING_STRIKES  = 406834
local CRUSADER_STRIKE    = 35395
local WAKE_OF_ASHES      = 255937
local JUDGMENT           = 220637
local BLADE_OF_JUSTICE   = 184575
local EXECUTION_SENTENCE = 408386
local FINAL_RECKONING    = 408386
local HAMMER_OF_WRATH    = 24275

-- -------- Talents --------
local TALENT_BOUNDLESS_JUDGMENT = 405278
local TALENT_HOLY_BLADE         = 383342
local TALENT_DIVINE_AUXILIARY   = 406158
local TALENT_SANCTIFY           = 382536

-- -------- Generators --------
local GEN = {
  [TEMPLAR_STRIKES]    = 1,
  [TEMPLAR_SLASH]      = 1,
  [CRUSADING_STRIKES]  = 1,
  [CRUSADER_STRIKE]    = 1,
  [WAKE_OF_ASHES]      = 3,
  [JUDGMENT]           = 1,  -- becomes 2 with Boundless Judgment
  [BLADE_OF_JUSTICE]   = 1,  -- becomes 2 with Holy Blade
  [EXECUTION_SENTENCE] = 0,  -- becomes 3 with Divine Auxiliary
  [FINAL_RECKONING]    = 0,  -- becomes 3 with Divine Auxiliary
  [HAMMER_OF_WRATH]    = 1,  -- becomes 2 with Sanctify & target <20%
}

function PHP.GetHPGeneratedFromSpell(id, amtFromCLEU)
  local base = GEN[id]; if base==nil then return nil end
  if id==JUDGMENT then
    base = IsTalent(TALENT_BOUNDLESS_JUDGMENT) and 2 or 1
  elseif id==BLADE_OF_JUSTICE then
    base = IsTalent(TALENT_HOLY_BLADE) and 2 or 1
  elseif id==EXECUTION_SENTENCE or id==FINAL_RECKONING then
    base = IsTalent(TALENT_DIVINE_AUXILIARY) and 3 or 0
  elseif id==HAMMER_OF_WRATH then
    local p=TargetHPpct()
    base = (p and p<20 and IsTalent(TALENT_SANCTIFY)) and 2 or 1
  end
  if amtFromCLEU~=nil then
    return math.min(math.max(base or 0, amtFromCLEU), 5)
  end
  return base
end

-- -------- IDs (Spenders) --------
local TEMPLARS_VERDICT        = 85256
local FINAL_VERDICT           = 383328
local DIVINE_STORM            = 53385
local DIVINE_HAMMER           = 198034
local WORD_OF_GLORY           = 85673
local SHIELD_OF_THE_RIGHTEOUS = 53600
local LIGHT_OF_DAWN           = 85222
local RADIANT_DECREE          = 385438
local JUSTICARS_VENGEANCE     = 215661
local HAMMER_OF_LIGHT         = 427453

-- -------- Spenders baseline --------
PHP.HolyPowerSpenders = {
  [TEMPLARS_VERDICT]        = 3,
  [FINAL_VERDICT]           = 3,
  [DIVINE_STORM]            = 3,
  [DIVINE_HAMMER]           = 3,
  [WORD_OF_GLORY]           = 3,
  [SHIELD_OF_THE_RIGHTEOUS] = 3,
  [LIGHT_OF_DAWN]           = 3,
  [RADIANT_DECREE]          = 3,
  [JUSTICARS_VENGEANCE]     = 5,
  [HAMMER_OF_LIGHT]         = 5,
}

-- Exports
PHP.HolyPowerGenerators = GEN
PHP.HPGenByName   = PHP.HPGenByName   or {}
PHP.HPSpendByName = PHP.HPSpendByName or {}