#include <user/comparatorApiDesc.h>
#include <user/senseApiDesc.h>

namespace smo {
namespace comparator_lib {
namespace core {
namespace {

static const char COMPARATOR_LIB_NAME[] = "coreComp";
static const char BODY_SPOT_COMPARATOR_TYPE_NAME[] = "bodySpot";
static const char STIM_FEAT_COMPARATOR_TYPE_NAME[] = "stimFeat";
static const char SIMULTANEITY_STAMP_COMPARATOR_TYPE_NAME[] =
	"simultaneityStamp";

class BodySpotComparator
:	public cologex::Comparator
{
public:
	BodySpotComparator()
	:	cologex::Comparator(MentalEntity::Id{0})
	{}

	cologex::ComparatorTypeId getTypeId() const override
	{
		return cologex::ComparatorTypeId{
			cologex::SMO_COMPARATOR_VENDOR_ID,
			cologex::SMO_COMPARATOR_TYPE_BODY_SPOT
		};
	}
};

class StimFeatComparator
:	public cologex::Comparator
{
public:
	StimFeatComparator()
	:	cologex::Comparator(MentalEntity::Id{0})
	{}

	cologex::ComparatorTypeId getTypeId() const override
	{
		return cologex::ComparatorTypeId{
			cologex::SMO_COMPARATOR_VENDOR_ID,
			cologex::SMO_COMPARATOR_TYPE_STIM_FEAT
		};
	}
};

class SimultaneityStampComparator
:	public cologex::Comparator
{
public:
	SimultaneityStampComparator()
	:	cologex::Comparator(MentalEntity::Id{0})
	{}

	cologex::ComparatorTypeId getTypeId() const override
	{
		return cologex::ComparatorTypeId{
			cologex::SMO_COMPARATOR_VENDOR_ID,
			cologex::SMO_COMPARATOR_TYPE_SIMULTANEITY_STAMP
		};
	}
};

std::unique_ptr<cologex::Comparator> makeBodySpotComparator()
{
	return std::make_unique<BodySpotComparator>();
}

std::unique_ptr<cologex::Comparator> makeStimFeatComparator()
{
	return std::make_unique<StimFeatComparator>();
}

std::unique_ptr<cologex::Comparator> makeSimultaneityStampComparator()
{
	return std::make_unique<SimultaneityStampComparator>();
}

cologex::ComparatorLibDesc buildComparatorLibDesc()
{
	return cologex::ComparatorLibDesc{
		.name = COMPARATOR_LIB_NAME,
		.exportedComparatorTypes = {
			cologex::ExportedComparatorTypeDesc{
				.name = BODY_SPOT_COMPARATOR_TYPE_NAME,
				.typeId = cologex::ComparatorTypeId{
					cologex::SMO_COMPARATOR_VENDOR_ID,
					cologex::SMO_COMPARATOR_TYPE_BODY_SPOT
				},
				.getNewInstance = makeBodySpotComparator
			},
			cologex::ExportedComparatorTypeDesc{
				.name = STIM_FEAT_COMPARATOR_TYPE_NAME,
				.typeId = cologex::ComparatorTypeId{
					cologex::SMO_COMPARATOR_VENDOR_ID,
					cologex::SMO_COMPARATOR_TYPE_STIM_FEAT
				},
				.getNewInstance = makeStimFeatComparator
			},
			cologex::ExportedComparatorTypeDesc{
				.name = SIMULTANEITY_STAMP_COMPARATOR_TYPE_NAME,
				.typeId = cologex::ComparatorTypeId{
					cologex::SMO_COMPARATOR_VENDOR_ID,
					cologex::SMO_COMPARATOR_TYPE_SIMULTANEITY_STAMP
				},
				.getNewInstance = makeSimultaneityStampComparator
			}
		}
	};
}

} // namespace
} // namespace core
} // namespace comparator_lib
} // namespace smo

extern "C" smo::SMO_GET_COMPARATOR_LIB_DESC_FN_TYPEDEF
	SMO_GET_COMPARATOR_LIB_DESC_FN_NAME;

const smo::cologex::ComparatorLibDesc& SMO_GET_COMPARATOR_LIB_DESC_FN_NAME(
	const smo::stim_buff::SmoCallbacks& callbacks)
{
	(void)callbacks;
	static const smo::cologex::ComparatorLibDesc comparatorLibDesc =
		smo::comparator_lib::core::buildComparatorLibDesc();
	return comparatorLibDesc;
}
