#pragma once

#include <string>
#include <cstdio>
#include <cstdint>
#include <memory.h>

enum class MCError : uint8_t
{
	NONE = 0,
	UNKNOWN_ERROR,
	NUM_ERRORS
};

// Valid range: [-1, 1]
typedef float motorVel_normalized;

class MC
{
  public:
	MC(std::string id, const uint32_t maxVelocity_cps);

	const std::string mcID;

	virtual MCError start() = 0;
	virtual MCError stop() = 0;
	virtual MCError sleep() = 0;

	virtual MCError setSpeed(const motorVel_normalized vel) = 0;

	// Returns the current velocity of the motor over the range [-MAX_VEL, MAX_VEL]
	virtual MCError getSpeed_normalized(motorVel_normalized& vel) = 0;

	uint32_t maxMotorVelocity_cps();

  protected:
	virtual ~MC() = default;

	virtual MCError init() = 0;

	void logLine(std::string comment);

	const std::string getEngFileHeader();

	// Maximum motor velocity, in counts per second. This limit is assumed to be symetric,
	// meaning it can drive the motor at the maximum velocity in both directions.
	const uint32_t maxVel_cps;

	// clange-format off
	const std::string engFileHeader = "_msgID\t"
									  "dateTime_Z\t"
									  "state\t"
									  "comment";
	// clange-format on
};
