local this = {}

function this:rsp_syncHouseInfo(data)
  local mapInfo = data.map_info
  if table.isEmpty(mapInfo) or table.isEmpty(mapInfo.home) or table.isEmpty(mapInfo) then
    return
  end
  for i, build in ipairs(mapInfo.home.builds or {}) do
    local buildType = L_HomeManager:getBuildTypeById(build.build_id)
    if buildType == L_Const.WorldMapBuildType.WMBT_HOUSE then
      local guid = build.guid
      self.data.houseInfos[guid] = (self.data.houseInfos[guid] or self.dataCls.homeHouseInfo.new(guid)):populate(build)
    end
  end
  for i, guid in ipairs(mapInfo.home.del_builds or {}) do
    self.data.houseInfos[guid] = nil
  end
  printf("\229\144\140\230\173\165\230\176\145\229\174\133\229\174\140\230\136\144", self.data.houseInfos)
  self:call(self.event.residentDataUpdate)
end

function this:rsp_syncResident(data)
  for _, resident in ipairs(data.resident_people_info or {}) do
    local id = resident.id
    self.data.residentInfos[id] = (self.data.residentInfos[id] or self.dataCls.homeResidentInfo.new(id)):populate(resident)
  end
  for _, residentId in ipairs(data.del_people_id or {}) do
    self.data.residentInfos[residentId] = nil
  end
  printf("\229\144\140\230\173\165\228\186\186\229\143\163\229\174\140\230\136\144", self.data.residentInfos)
  self:call(self.event.residentDataUpdate)
end

function this:req_fireResident(buildGuid, roomId, cb)
  local data = {guid = buildGuid, room_id = roomId}
  L_Net:sendMessage(MsgGenCode.CSProtoDeletPeople, data, cb)
end

function this:req_hireResident(buildGuid, roomId)
  local data = {guid = buildGuid, room_id = roomId}
  L_Net:sendMessage(MsgGenCode.CSProtoHomePeopleRefresh, data)
end

function this:req_refreshResident(residentId, callback)
  local data = {u32 = residentId}
  L_Net:sendMessage(MsgGenCode.CSProtoResidentInfoGet, data, callback)
end

return this
