local ctrl = {}
local BadOneResPath = "Assets/_Art_LastWar/Models/Environment/Build/Posunweilan/prefab/A_build_posunweilan.prefab"
ctrl.badOneHandle = nil
ctrl.goodOne = nil

function ctrl.Update()
  local fenceBuilding = DataCenter.BuildManager:GetBuildingDataByPointId(3951)
  if fenceBuilding == nil then
    return
  end
  ctrl.goodOne = DataCenter.CityZoneMgr.gameObject
  if fenceBuilding.level < 1 then
    ctrl.ShowTheBadOne()
  else
    ctrl.ShowTheGoodOne()
  end
end

function ctrl.HideTheBadOne()
  if not IsNull(ctrl.badOneHandle) and not IsNull(ctrl.badOneHandle.gameObject) then
    ctrl.badOneHandle.gameObject:SetActive(false)
  end
end

function ctrl.ShowTheBadOne()
  if not IsNull(ctrl.goodOne) then
    ctrl.goodOne:SetActive(false)
  end
  if IsNull(ctrl.badOneHandle) then
    ctrl.badOneHandle = CS.GameEntry.Resource:InstantiateAsync(BadOneResPath)
    ctrl.badOneHandle:completed("+", function(handle)
    end)
  elseif not IsNull(ctrl.badOneHandle.gameObject) then
    ctrl.badOneHandle.gameObject:SetActive(true)
  end
end

function ctrl.ShowTheGoodOne()
  if not IsNull(ctrl.goodOne) then
    ctrl.goodOne:SetActive(true)
  end
  if not IsNull(ctrl.badOneHandle) then
    ctrl.badOneHandle:RealDestroy()
    ctrl.badOneHandle = nil
  end
end

function ctrl.Clear()
  if not IsNull(ctrl.badOneHandle) then
    ctrl.badOneHandle:RealDestroy()
    ctrl.badOneHandle = nil
  end
end

return ctrl
