local GovernmentTemplate = BaseClass("GovernmentTemplate")
local __init = function(self)
  self.id = 0
  self.name = ""
  self.effect = {}
  self.effectOrder = {}
  self.conqueror_effect = {}
  self.conqueror_effectOrder = {}
  self.icon = ""
  self.is_positive = 0
  self.title_name = 0
  self.status_id = 0
end
local __delete = function(self)
  self.id = 0
  self.name = ""
  self.effect = {}
  self.effectOrder = {}
  self.conqueror_effect = {}
  self.conqueror_effectOrder = {}
  self.icon = ""
  self.is_positive = 0
  self.title_name = 0
  self.status_id = 0
end

function GovernmentTemplate:InitData(row)
  if row == nil then
    return
  end
  self.id = tonumber(row:getValue("id")) or 0
  self.type = tonumber(row:getValue("type")) or 0
  self.name = row:getValue("name") or ""
  self.order = tonumber(row:getValue("order")) or 0
  self.icon = string.format(LoadPath.UIGovernment, row:getValue("icon") or "")
  self.iconName = row:getValue("icon") or ""
  self.is_positive = row:getValue("is_positive") or 0
  self.status_id = row:getValue("status_id") or 0
  local effectStr = row:getValue("effect")
  if effectStr ~= nil and effectStr ~= nil then
    for item in string.gmatch(effectStr, "([^|]+)|?") do
      local effect_id, effect_num = string.match(item, "(%d+)[,;](%d+.?%d*)")
      if effect_id ~= nil and effect_num ~= nil then
        self.effect[toInt(effect_id)] = tonumber(effect_num)
        table.insert(self.effectOrder, toInt(effect_id))
      end
    end
  end
  self.title_name = tonumber(row:getValue("title_name")) or 0
  effectStr = row:getValue("conqueror_effect")
  if effectStr ~= nil and effectStr ~= nil then
    for item in string.gmatch(effectStr, "([^|]+)|?") do
      local effect_id, effect_num = string.match(item, "(%d+)[,;](%d+.?%d*)")
      if effect_id ~= nil and effect_num ~= nil then
        self.conqueror_effect[toInt(effect_id)] = tonumber(effect_num)
        table.insert(self.conqueror_effectOrder, toInt(effect_id))
      end
    end
  end
end

GovernmentTemplate.__init = __init
GovernmentTemplate.__delete = __delete
return GovernmentTemplate
