#include <sstream>
#include "CarSink.h"
#include "../Simulator.h"
#include "Car.h"
#include "../Logger.h"

CarSink::CarSink(Sector* sector):
	SimulationObject(),
	_sector(sector)
{
}

CarSink::~CarSink()
{
}

void CarSink::performStep()
{
	if (_sector->getNumOfCars() > 0) {
		Car* car = _sector->getCars().at(0);
		_INFO("CarSink[" << getID() << "]: destroying car[" << car->getID() << "] in sector[" << _sector->getID() << "]");
		Simulator::getInstance()->scheduleForRemoval(car);
	}
}

std::string CarSink::toString() const
{
	std::ostringstream oss;
	oss << "CarSink[" << getID() << "]";
	return oss.str();
}

std::ostream& operator<<(std::ostream& os, const CarSink& sink)
{
	os << sink.toString();
	return os;
}
