local SkinManager = class("SkinManager", BaseModule)

function SkinManager:init()
    self:addEventListener(EventManager.CUSTOM_EVENT.GETED_REWARD_SUCCESS, function(rewards)
        self:checkUnlockSkin(rewards)
    end)
end

-- 检查解锁皮肤
function SkinManager:checkUnlockSkin(checkData)
    if type(checkData) ~= "table" then
        return
    end

    for index, reward in ipairs(checkData) do
        if reward.type == GConst.REWARD_TYPE.ITEM and ConfigManager:getConfig("item")[reward.item.id].type == GConst.ItemConst.ITEM_TYPE.SKIN  then
            DataManager.SkinData:onUnlockSkin(reward.item.id)
        end
    end
end

-- 使用皮肤
function SkinManager:reqChangeSkin(heroId, skinId)
    self:sendMessage(ProtoMsgType.FromMsgEnum.HeroChangeSkinReq, {id = heroId, skin_id = skinId}, {}, self.rspChangeSkin)
end

function SkinManager:rspChangeSkin(result)
    if result.err_code == GConst.ERROR_STR.SUCCESS then
        DataManager.SkinData:onUseSkin(result.reqData.id, result.reqData.skin_id)
    end
end

return SkinManager