#include <stdexcept>

#include <body/bodyThread.h>
#include <componentThread.h>
#include <director/directorThread.h>
#include <marionette/marionette.h>
#include <marionette/marionetteThread.h>
#include <mind.h>
#include <simulator/simulatorThread.h>
#include <subconsciousThread.h>
#include <world/worldThread.h>

namespace smo {
namespace mrntt {

boost::asio::io_context &MrnttThreadTag::io_context() noexcept
{
	return thread->getIoContext();
}

} // namespace mrntt

namespace body {

boost::asio::io_context &BodyThreadTag::io_context()
{
	if (!mind::globalMind) {
		throw std::runtime_error(
			"BodyThreadTag: globalMind not initialized");
	}

	return mind::globalMind->body.thread->getIoContext();
}

} // namespace body

namespace director {

boost::asio::io_context &DirectorThreadTag::io_context()
{
	if (!mind::globalMind) {
		throw std::runtime_error(
			"DirectorThreadTag: globalMind not initialized");
	}

	return mind::globalMind->director.thread->getIoContext();
}

} // namespace director

namespace simulator {

boost::asio::io_context &SimulatorThreadTag::io_context()
{
	if (!mind::globalMind) {
		throw std::runtime_error(
			"SimulatorThreadTag: globalMind not initialized");
	}

	return mind::globalMind->canvas.thread->getIoContext();
}

} // namespace simulator

boost::asio::io_context &SubconsciousThreadTag::io_context()
{
	if (!mind::globalMind) {
		throw std::runtime_error(
			"SubconsciousThreadTag: globalMind not initialized");
	}

	return mind::globalMind->subconscious.thread->getIoContext();
}

boost::asio::io_context &WorldThreadTag::io_context()
{
	if (!mind::globalMind) {
		throw std::runtime_error(
			"WorldThreadTag: globalMind not initialized");
	}

	return mind::globalMind->world.thread->getIoContext();
}

} // namespace smo
