#pragma once

#include <cstdint>
#include <string>

#include "run_config.hpp"
#include "switch_driver.hpp"

namespace radar::drivers {

/**
 * @brief Runtime settings for the H7992 GPIO switch driver.
 */
struct H7992MinimalDriverSettings {
    std::string name{};
    config::DriverMode mode = config::DriverMode::Native;
    std::uint32_t positions = 4;
    std::uint32_t default_position = 0;
    std::string gpio_chip = "/dev/gpiochip0";
    std::int32_t pin_a = 17;
    std::int32_t pin_b = 27;
};

/**
 * @brief Minimal H7992 implementation for fast position switching.
 *
 * Native mode uses Linux GPIO character-device API (uAPI v2).
 * Mock mode keeps state in memory without touching hardware.
 */
class H7992MinimalDriver final : public SwitchDriver {
  public:
    explicit H7992MinimalDriver(H7992MinimalDriverSettings settings);

    void open() override;
    void close() override;
    [[nodiscard]] auto position_count() const -> std::uint32_t override;
    void switch_to(std::uint32_t position) override;

  private:
    void open_native();
    void close_native();
    void switch_native(std::uint32_t position);

    H7992MinimalDriverSettings settings_{};
    bool is_open_ = false;
    std::uint32_t current_position_ = 0;
    int chip_fd_ = -1;
    int line_fd_ = -1;
};

}  // namespace radar::drivers
