local TeamShopCustomerSystem = inherited("TeamShopCustomerSystem", SystemMap)

function TeamShopCustomerSystem:new()
	local ms = instance(self)
	ms.team_masks = {}
	return ms
end

TeamShopCustomerSystem.key = "team_shop_customers_target"


function TeamShopCustomerSystem:wants(ent)
	return ent.aspects.shop_customer and ent.aspects.team_owned
end

function TeamShopCustomerSystem:dynamic_wants(ent)
	return ent.aspects.shop_customer and ent.aspects.team_owned and not ent.dead
end

function TeamShopCustomerSystem:ent_added(ent)
	local team = ent.team
	if team then
		local mask = self.team_masks[team]
		if not mask then
			mask = {}
			self.team_masks[team] = mask
		end
		mask[ent] = true
	end
end

function TeamShopCustomerSystem:ent_removed(ent)
	local team = ent.team
	if team then
		local mask = self.team_masks[team]
		if mask then
			mask[ent] = nil
		end
	end
end


function TeamShopCustomerSystem:ent_leaving_team(ent, team)
	self:ent_removed(ent)
end

function TeamShopCustomerSystem:ent_joined_team(ent, team)
	self:ent_added(ent)
end


function TeamShopCustomerSystem:get_target_map(team)
	return self.team_masks[team]
end

return TeamShopCustomerSystem