local ItemManager = class("ItemManager", BaseModule)

function ItemManager:getItemIcon(id)
    return GConst.ATLAS_PATH.ICON_ITEM, ConfigManager:getConfig("item")[id].icon
end

function ItemManager:getItemName(id)
    return I18N:getText("item", id, "name")
end

function ItemManager:getItemDesc(id)
    return I18N:getText("item", id, "desc")
end

function ItemManager:getItemType(id)
    return ConfigManager:getConfig("item")[id].type
end

function ItemManager:rspRecoveryNtf(result)
    if result and result.id == GConst.ItemConst.ITEM_ID_VIT then
        if result.count and result.count > 0 then
            BIReport:postVitGet(result.count, BIReport.ITEM_GET_TYPE.OFFLINE_RECOVERY)
        end
    end
end

--@region 协议
-- 宝箱奖励
BIReport.ITEM_GET_TYPE.BOX_REWARD = "box_reward"
BIReport.ITEM_GET_TYPE.SELECT_BOX_REWARD = "select_box_reward"

function ItemManager:reqOpenBoxReward(id, count, idx)
    -- idx只有自选奖励才有
    local bi = BIReport.ITEM_GET_TYPE.BOX_REWARD
    if idx and idx > 0 then
        bi = BIReport.ITEM_GET_TYPE.SELECT_BOX_REWARD
    end
    self:sendMessage(ProtoMsgType.FromMsgEnum.ItemUseReq, {id = id, count = count, index = idx}, self.rspOpenBoxReward, bi)
end

function ItemManager:rspOpenBoxReward(result)
    if result.err_code ~= GConst.ERROR_STR.SUCCESS then
        return
    end

    GFunc.showRewardBox(result.rewards)
    DataManager.BagData.ItemData:setDirty()
end
--@endregion
return ItemManager