local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    residentInfos = {},
    houseInfos = {}
  }
end

function this:getResidentInfo(id)
  return self.data.residentInfos[id]
end

function this:getAllResident()
  return self.data.residentInfos
end

function this:getHouseInfo(id)
  return self.data.houseInfos[id]
end

function this:getAllHouse()
  return self.data.houseInfos
end

function this:getRestResidentNum()
  local num = 0
  for _, resident in pairs(self.data.residentInfos) do
    if resident.workBuilding == 0 then
      num = num + 1
    end
  end
  return num
end

function this:getMaxResidentNum()
  local num = 0
  for _, house in pairs(self.data.houseInfos) do
    num = num + #house.roomInfo
  end
  return num
end

function this:getResidentByBuilding(buildingGuid, isCollect)
  local inHome = not isCollect
  local res = {}
  for _, resident in pairs(self.data.residentInfos) do
    if resident.workBuilding == buildingGuid and inHome == resident.is_in_home then
      table.insert(res, resident)
    end
  end
  return res
end

function this:getFoodCostSum()
  local homeResidentLevelTpl = L_GameTpl:getHomeResidentLevelTpl()
  local foodCostSum = 0
  for id, resident in pairs(self.data.residentInfos) do
    local tpl_resident_level = homeResidentLevelTpl:getTplById(resident.level or 1)
    local foodCost = homeResidentLevelTpl:getFoodCost(tpl_resident_level)
    foodCostSum = foodCostSum + foodCost
  end
  return foodCostSum
end

return this
