--COMBAT_LOG_EVENT_UNFILTERED
function(e, ...)
    local se = select(2, ...)
    if se == "SPELL_AURA_APPLIED" then
        local caster, target, buff = select(5, ...), select(9, ...), select(13, ...)
        if caster == UnitName("player") and target == UnitName("player") and buff == "Bulwark of Flame" then
            WeakAuras.ScanEvents("FUCKAGE_BEGIN")
            C_Timer.After(3, function() WeakAuras.ScanEvents("FUCKAGE_STOP") end)
        end
    end
end

--FUCKAGE_BEGIN FUCKAGE_STOP
function(e)
    if e == "FUCKAGE_BEGIN" then
        aura_env.fuckage = 1
        if UnitBuff("player", "Bulwark of Flame") then
            local absorb = select(17, UnitBuff("player", "Bulwark of Flame"))
            absorb = tonumber(absorb)
            aura_env.maxAbsorb = absorb
        end
    elseif e == "FUCKAGE_STOP" then
        aura_env.fuckage = 0
    end
end

--EVERY FRAME TRIGGER
function()
    if aura_env.fuckage == 1 then
        return true
    else
        return false
    end
end

--EVERY FRAME DURATION
function()
    if aura_env.fuckage == 1 then
        if UnitBuff("player", "Bulwark of Flame") then
            local absorb = select(17, UnitBuff("player", "Bulwark of Flame"))
            absorb = tonumber(absorb)
            if absorb > aura_env.maxAbsorb then
                aura_env.maxAbsorb = absorb
            end
            aura_env.absorb = absorb
            return absorb, aura_env.maxAbsorb, 1
        end
    else
        return 0, 0, 0
    end
end

--NAME INFO
function()
    return aura_env.shorten(aura_env.maxAbsorb)
end

--STACKS
function()
    return aura_env.shorten(aura_env.absorb)
end

--INIT
aura_env.maxAbsorb = 0
aura_env.fuckage = 0
aura_env.absorb = 0
aura_env.shorten = function(val)
    local function round(var, n)
        if (n) then
            var = math.floor((var * 10 ^ n) + 0.5) / (10 ^ n)
        else
            var = math.floor(var + 0.5)
        end
        return var
    end
    local n = 2
    if val < 1e3 then
        return round(val, n)
    elseif val > 1e3 and val < 1e6 then
        return round(val / 1e3, n) .. "k"
    elseif val > 1e6 and val < 1e9 then
        return round(val / 1e6, n) .. "M"
    elseif val > 1e9 then
        return round(val / 1e9, n) .. "G"
    end
end
