local HeroFundManager = class("HeroFundManager", BaseModule)

function HeroFundManager:showMainUI()
    UIManager:showUI("app/ui/activity/hero_fund/hero_fund_ui")
end

function HeroFundManager:reqHeroFundAward(level, rewardType)
    if not DataManager.HeroFundData:getIsOpen() then
        GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_EDSC))
        return
    end
    -- 直接一键领取
    local curLevel = DataManager.HeroFundData:getWaveLevel()
    local heroIdWithLv = {}
    for id = 1, curLevel do
        if DataManager.HeroFundData:getFreeCanGet(id) then
            table.insert(heroIdWithLv, {id = id, grade = 0})
        end

        if DataManager.HeroFundData:getProCanGet(id) then
            table.insert(heroIdWithLv, {id = id, grade = 1})
        end

        if DataManager.HeroFundData:getUtralCanGet(id) then
            table.insert(heroIdWithLv, {id = id, grade = 2})
        end
    end

    if not heroIdWithLv[1] then
        return
    end

    local params = {
        id_with_lv = heroIdWithLv
    }

    self:sendMessage(ProtoMsgType.FromMsgEnum.HeroFundAwardReq, params, {}, self.rspHeroFundAward, BIReport.ITEM_GET_TYPE.ACT_HERO_FUND)
end

function HeroFundManager:rspHeroFundAward(result)
    if result.err_code == GConst.ERROR_STR.SUCCESS then
        DataManager.HeroFundData:gotReward(result.id_with_lv)
        GFunc.showRewardBox(result.rewards)
    end
end

function HeroFundManager:purcharse(id)
    PayManager:purchasePackage(id, PayManager.PURCHARSE_TYPE.ACT_GIFT)
end

return HeroFundManager