#include "StateBase.hpp"

/// Strings associated with each CPF system state.
/// The ordering of this array must match the ordering within the
/// StateNames enum. numStates does not get a value.
std::string_view state_names[StateNames::numStates] =
{
	"Not Running",
	"First State",
	"Second State"
};

std::string_view getNameForStateID(StateNames id)
{
	return state_names[static_cast<unsigned>(id)];
}

StateBase::StateBase(StateNames id, uint32_t timeout) : stateTimeout(timeout), state_id_(id)
{
}

void StateBase::enter()
{
	std::cout << "Entering state: " << getNameForStateID(state_id_) << std::endl;

	/// Invoke the subclass's enter actions
	doStateEntry();
}

void StateBase::exit(bool timeout)
{
	std::cout << "Exiting state: " << getNameForStateID(state_id_) << std::endl;

	/// Invoke subclasses's exit actions
	doStateExit(timeout);

	/// Perform any final state exit actions
	smLogEngLine("Running StateBase::StdStateExit()");
	if(timeout)
	{
		smLogEngLine("StateBase::StdStateExit() invoked with timeout = true");
	}
}

StateNames StateBase::process(const event_t& event)
{
	smLogEngLine("Processing incoming event");
	return doStateActions(event);
}

void StateBase::smLogEngLine(std::string comment)
{
	std::cout << "[State][" << getNameForStateID(state_id_) << "] " << comment << std::endl;
}

void StateBase::logEngFileHeader()
{
//	Logger::logEngLine(ALWAYS, stmchEngMsgID, "dateTime_Z", "state", "comment");
//	Logger::logEngLine(ALWAYS, stmchEngMsgID, "text",		"text",		"text");
}
