local this = {}
local _homeBuildingCollectionTpl = L_GameTpl:getHomeBuildingCollectionTpl()

function this:checkCondition(entity, param)
  return true
end

function this:executeInteract(entity, param)
  local paramTable = string.split(param, ",")
  local guid = tonumber(paramTable[2])
  local serverData = L_CollectionStore:getCollection(guid)
  if math.isEmpty(serverData.build_id) then
    local buildings = _homeBuildingCollectionTpl:getTplByCollectionId(guid)
    local materialList = _homeBuildingCollectionTpl:getMaterial(buildings[1])
    local item = {}
    for i, v in pairs(materialList) do
      local itemType, itemId, ItemNum = v[1], v[2], v[3]
      local hasNum = L_ItemTplManager:getItemNum(itemType, itemId)
      table.insert(item, {
        itemType = itemType,
        itemId = itemId,
        itemNumTxt = string.format("%s/%s", L_GameUtil.fillColor(hasNum, ItemNum > hasNum and L_Const.colorHtml.red001 or L_Const.colorHtml.white001), v[3])
      })
    end
    L_GameUtil.showCommonTip({
      txtTitle = L_WordsTpl:getValue("notice_interact_fixBuilding_02"),
      txtContent = L_WordsTpl:getValue("notice_interact_fixBuilding_01", {
        [0] = _homeBuildingCollectionTpl:getName(buildings[1])
      }),
      itemList = item,
      confirmCallback = function()
        if L_CollectionManager:checkCanFixCollectionBuilding(guid) then
          L_CollectionManager:reqBuildCollect(guid)
        end
      end
    })
  else
    L_UI:open("pageCollection", {entity = entity, guid = guid})
  end
end

function this:getDisplayName(entity, param)
  local paramTable = string.split(param, ",")
  return paramTable[1]
end

return this
