// =============================================================================
//  modes/standby.h -- pilot mode state (Sprint 1)
// =============================================================================
//
//  Holds the global "what mode is the pilot in" flag. In Sprint 1 the only
//  mode that does anything real is STANDBY. The other Phase 1 modes
//  (HEADING_HOLD, TRUE_COURSE, TRACK_KEEPING, DODGE) are reserved in the
//  enum but cannot be entered yet -- attempting to set them logs a warning
//  and stays in STANDBY.
//
//  Later sprints expand this module into a proper state machine driven by
//  the safety system and the operator's Modbus commands.
// =============================================================================

#pragma once

#include <cstdint>

namespace arautopilot::modes {

enum class Mode : uint8_t {
    STANDBY = 0,
    HEADING_HOLD = 1,
    TRUE_COURSE = 2,
    TRACK_KEEPING = 3,
    DODGE = 4,
};

/// Initialise to STANDBY. Must be called once from setup().
void mode_init();

/// Atomically read the current mode.
Mode current_mode();

/// True if and only if current_mode() == STANDBY.
bool is_standby();

/// Try to enter `m`. In Sprint 1 only STANDBY is accepted; anything else
/// is rejected with a warning. Returns true on success.
bool request_mode(Mode m);

/// Force-return to STANDBY (called by the safety system on auto-disengage,
/// watchdog reset, or the DI1 physical button).
void force_standby(const char* reason);

}  // namespace arautopilot::modes
