local GovernmentEffect = BaseClass("GovernmentEffect")
local official_root_path = "Transform"
local icon_path = "Transform/icon"

function GovernmentEffect:OnCreate(go)
  if go ~= nil then
    self.request = go
    self.gameObject = go.gameObject
    self.transform = go.gameObject.transform
    self.official_root = self.transform:Find(official_root_path)
    self.king_icon = self.transform:Find(icon_path):GetComponent(typeof(CS.UnityEngine.SpriteRenderer))
  end
end

function GovernmentEffect:OnDestroy()
  self.timer_action = nil
  self.gameObject = nil
  self.transform = nil
  self.official_root = nil
end

function GovernmentEffect:ReInit(governmentId, lod, uuid)
  self.governmentId = governmentId
  self.bUuid = uuid
  self.hasOfficialPosition = false
  if self.official_root ~= nil and governmentId ~= nil and governmentId ~= "" and governmentId ~= 0 then
    local config = DataCenter.GovernmentTemplateManager:GetTemplate(governmentId)
    if config ~= nil then
      self.official_root.gameObject:SetActive(true)
      self.official_root.transform:Set_localScale(1, 1, 1)
      self.king_icon:LoadSprite(config.icon)
      if config.order == 0 then
        self.king_icon.transform:Set_localScale(1.2, 1.5, 1.2)
      else
        self.king_icon.transform:Set_localScale(1, 1, 1)
      end
      self.hasOfficialPosition = true
    end
  end
  self:OnCameraChangeLod(toInt(lod))
end

function GovernmentEffect:OnCameraChangeLod(lod)
  if self.gameObject == nil or IsNull(self.gameObject) then
    return
  end
  self.lod = lod
  if self.hasOfficialPosition and lod < 3 then
    self.official_root.gameObject:SetActive(true)
    self.official_root.transform:Set_localScale(1, 1, 1)
  else
    self.official_root.gameObject:SetActive(false)
    self.official_root.transform:Set_localScale(0, 0, 0)
  end
end

return GovernmentEffect
