local TalentData = class("TalentData", BaseData)

local TalentCfg = ConfigManager:getConfig("talent")
local PlayerExpCfg = ConfigManager:getConfig("player_exp")

function TalentData:setDirty()
    self.data.isDirty = not self.data.isDirty
end

function TalentData:ctor()
	self.data.isDirty = false
end

function TalentData:init(data)
	data = data or GConst.EMPTY_TABLE
	self.stage = data.stage
	self.levels = data.levels or {}
end

function TalentData:clear()
end

function TalentData:getCfgList()
	return TalentCfg
end

function TalentData:getPlayerExpCfgList(stage)
	if stage then
		return PlayerExpCfg[stage]
	end
	return PlayerExpCfg
end

function TalentData:getStage()
	return self.stage
end

function TalentData:checkStage()
	local lv = DataManager.PlayerData:getLv()
	return lv >= self.stage, self.stage
end

function TalentData:getLevels(id)
	if id then
		return self.levels[id] or 0
	end
	return self.levels
end

function TalentData:onUpgrade(data)
	self.upData = data
	self.stage = data.stage
	self.levels[data.id] = data.level
	self:setDirty()
end

function TalentData:getUpData()
	local data = self.upData
	self.upData = nil
	return data
end

return TalentData