--[[============================================================================
  This file is a part of ChampionBar

  Copyright (C) 2015 Scott Yeskie (Sasky)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  ============================================================================]]

---
--- Create new type for Enlightenment Pool
---
ChampionBar = ChampionBar or {}
local EPBarType = ZO_Object:Subclass()
ChampionBar.EPBarType = EPBarType
PPB_CLASS_EP = 5

function EPBarType:New(barTypeClass, barTypeId, ...)
    local obj = ZO_Object.New(self)
    obj.barTypeClass = barTypeClass
    obj.barTypeId = barTypeId
    obj.params = {...}
    obj:Initialize()
    obj:InitializeLastValues()
    return obj
end

function EPBarType:Initialize()
    self.barGradient = { ZO_ColorDef:New("EEFF66"), ZO_ColorDef:New("EEFF00") }
    self.levelTypeText = GetString(SI_EXPERIENCE_CHAMPION_RANK_LABEL)
    self.tooltipCurrentMaxFormat = ""--ZO_CommaDelimitNumber(ENLIGHTENMENT_MAX)
    self.icon = "EsoUI/Art/Champion/champion_points_health_icon-HUD-32.dds"
end

function EPBarType:InitializeLastValues()
    self.lastLevel = self:GetLevel()
    self.lastCurrent = self:GetCurrent()
end

function EPBarType:Equals(barTypeClass, ...)
    if(self.barTypeClass == barTypeClass) then
        for i = 1, select("#", ...) do
            local param = select(i, ...)
            if(param ~= self.params[i]) then
                return false
            end
        end
        return true
    end
    return false
end

function EPBarType:GetEnlightenedPool()
    if IsEnlightenedAvailableForCharacter() then
        return 1
    else
        return 0
    end
end

function EPBarType:GetEnlightenedTooltip()
    local ep = GetEnlightenedPool()
    local msg = {
        GetString(SI_ENLIGHTENMENT),
        ": ",
        ZO_CommaDelimitNumber(ep),
        "/",
        ZO_CommaDelimitNumber(self:GetLevelSize()),
        "\n(",
        math.floor(ep/10000)/10, --CP
        " ",
        GetString(SI_CHAMPION_POINTS),
        ")"
    }
    return table.concat(msg, "")
end

function EPBarType:GetSecondaryBarType()
    return nil
end

function EPBarType:GetLevelSize(rank)
    return ENLIGHTENMENT_MAX
end

function EPBarType:GetLevel()
    return GetPlayerChampionPointsEarned()
end

function EPBarType:GetCurrent()
    return ChampionBar.cpCurve(GetEnlightenedPool(),self:GetLevelSize())
end

function EPBarType:GetBarGradient()
    return self.barGradient
end

function EPBarType:GetShownAttribute()
    local level = self:GetLevel()
    if self:GetLevelSize(level) ~= nil then
        level = level + 1
    end
    return GetChampionPointAttributeForRank(level)
end

function EPBarType:GetLevelTypeText()
    return GetString(SI_EXPERIENCE_CHAMPION_RANK_LABEL)
end

function EPBarType:GetIcon()
    return "/esoui/art/champion/champion_star_burst.dds"
end