local HeroBountyTaskData = BaseClass("HeroBountyTaskData")
local __init = function(self)
  self.id = 0
  self.index = 0
  self.startTime = 0
  self.endTime = 0
  self.heroInfos = {}
  self.rewardList = {}
  self.rarity = 3
  self.name = ""
  self.description = ""
  self.needHeroNum = 0
  self.camp_requirements_list = {}
  self.star_requirements = 0
  self.rarity_requirements_list = {}
  self.exp_hero = 0
  self.taskTime = 0
end
local __delete = function(self)
  self.id = nil
  self.index = nil
  self.startTime = nil
  self.endTime = nil
  self.heroInfos = nil
  self.rewardList = nil
  self.rarity = nil
  self.name = nil
  self.description = nil
  self.needHeroNum = nil
  self.camp_requirements_list = nil
  self.star_requirements = nil
  self.rarity_requirements_list = nil
  self.exp_hero = nil
  self.taskTime = nil
end
local ParseData = function(self, message)
  if message == nil then
    return
  end
  if message.id ~= nil then
    self.id = message.id
  end
  if message.index ~= nil then
    self.index = message.index
  end
  if message.startTime ~= nil then
    self.startTime = message.startTime
  end
  self.heroInfos = {}
  if message.heroInfos ~= nil then
    local heroInfos = message.heroInfos
    for k, v in pairs(heroInfos) do
      local heroUuid = v.heroUuid
      local index = v.index
      if heroUuid ~= nil and index ~= nil then
        self.heroInfos[heroUuid] = index
      end
    end
  end
  if message.reward ~= nil then
    self.rewardList = DataCenter.RewardManager:ReturnRewardParamForView(message.reward)
    if self.rewardList == nil then
      self.rewardList = {}
    end
  end
  self:UpdateTemplate()
end
local UpdateTemplate = function(self)
  local config = LocalController:instance():getLine(TableName.HeroBounty, self.id)
  if config ~= nil then
    self.taskTime = tonumber(config:getValue("time_h"))
    if self.taskTime ~= nil and self.startTime > 0 then
      self.endTime = self.startTime + self.taskTime * 3600 * 1000
    else
      self.endTime = self.startTime
    end
    self.rarity = config:getValue("rarity")
    self.name = config:getValue("name")
    self.description = config:getValue("description")
    self.needHeroNum = config:getValue("hero_num")
    local camp_requirements = config:getValue("camp_requirements")
    self.camp_requirements_list = string.split(camp_requirements, ";")
    self.star_requirements = config:getValue("star_requirements")
    local rarity_requirements = config:getValue("rarity_requirements")
    self.rarity_requirements_list = string.split(rarity_requirements, ";")
    self.exp_hero = config:getValue("exp_hero")
    local item_show = config:getValue("item_show")
    if item_show ~= nil and item_show ~= "" then
      local rewardArr = string.split(item_show, "|")
      for k, v in pairs(rewardArr) do
        local reward = string.split(v, ";")
        if 2 <= #reward then
          local itemId = reward[1]
          local itemNum = reward[2]
          local hasId = false
          for a, b in pairs(self.rewardList) do
            if b.rewardType == RewardType.GOODS and b.itemId == itemId then
              hasId = true
            end
          end
          if hasId == false then
            local param = {}
            param.rewardType = RewardType.GOODS
            param.itemId = itemId
            param.count = itemNum
            table.insert(self.rewardList, param)
          end
        end
      end
    end
  end
end
HeroBountyTaskData.__init = __init
HeroBountyTaskData.__delete = __delete
HeroBountyTaskData.ParseData = ParseData
HeroBountyTaskData.UpdateTemplate = UpdateTemplate
return HeroBountyTaskData
