// Copyright 2023 Embedded Artistry LLC
// SPDX-License-Identifier: GPL-3.0-only OR Embedded Virtual Machine Commercial License
#pragma once
#include <event_base_types.hpp>
#include <system_time.hpp>

// These event IDs are unique to the solution
enum CPFEventIDs : event_id_t {
	ID_EntryAction,
	ID_GPSNewTimestampReady,
	ID_GPSNewPositionReady,
	ID_GPSCommunicationError,
};

struct EntryActionEvent : public EventBase<ID_EntryAction>
{};

struct GPSPositionReadyEvent : public EventBase<ID_GPSNewPositionReady>
{};

struct GPSTimestampReadyEvent : public EventBase<ID_GPSNewTimestampReady>
{
	/// Default constructor: Create, but don't specify values
	/// You can specify the values later by manually setting
	/// the member variables
	/// @code
	/// GPSTimestampReadyEvent e;
	/// e.gpsTimestamp = pubx04_timestamp;
	/// e.captureTimestamp = capture_timestamp;
	/// @endcode
	GPSTimestampReadyEvent() = default;

	GPSTimestampReadyEvent(systime::DateTimeStruct gps_time, uint64_t capture_time) :
		gpsTimestamp(gps_time), captureTimestamp(capture_time) {}

	/// Time returned from the GPS
	systime::DateTimeStruct gpsTimestamp;

	/// Capture timestamp that is associated with the GPS return,
	/// which allows the
	uint64_t captureTimestamp;
};

struct GPSCommunicationErrorEvent : public EventBase<ID_GPSCommunicationError>
{
	enum class Error : uint8_t
	{
		/// An error event was fired, but the error type was not specified
		ErrorUnknown,
		/// The GPS talked to us, but we got an unexpected response
		UnexpectedMessage,
		/// The GPS did not respond within the specified timeout
		Timeout,
		/// There was an error reported by the uunderlying communication bus
		BusError,
	};

	/// Default constructor: Create, but don't specify error type
	/// You can specify the error type later by manually setting
	/// the error member variable.
	/// @code
	/// GPSCommunicationErrorEvent e;
	/// e.error = GPSCommunicationErrorEvent::GPSError::Timeout;
	/// @endcode
	GPSCommunicationErrorEvent() : error(Error::ErrorUnknown) {}

	/// Create constructor and set error type
	GPSCommunicationErrorEvent(Error type) : error(type) {}

	Error error;
};
