#pragma once

#include <chrono>
#include <cstdint>
#include <filesystem>
#include <string>

namespace radar::processing {

enum class HistoryCommand {
    None,
    RemoveLast,
    ClearAll,
};

struct ProcessingLiveConfig {
    std::string processor_mode = "pass_through";
    float gain_db = 0.0F;
    float phase_deg = 0.0F;
    std::string bscan_axis = "abs";
    float bscan_cut_m = 0.824F;
    float bscan_max_depth_m = 1.0F;
    float bscan_gain = 1.0F;
    float bscan_start_freq_mhz = 100.0F;
    float bscan_stop_freq_mhz = 8800.0F;
    std::uint64_t history_command_seq = 0;
    HistoryCommand history_command = HistoryCommand::None;
};

class ProcessingLiveConfigLoader {
  public:
    explicit ProcessingLiveConfigLoader(std::string path);

    [[nodiscard]] auto current() const -> ProcessingLiveConfig;
    [[nodiscard]] auto refresh_if_needed() -> ProcessingLiveConfig;
    [[nodiscard]] auto revision() const -> std::uint64_t;

  private:
    [[nodiscard]] auto read_from_file() const -> ProcessingLiveConfig;

    std::string path_{};
    ProcessingLiveConfig current_{};
    std::filesystem::file_time_type last_write_time_{};
    bool has_last_write_time_ = false;
    std::uint64_t revision_ = 0;
    std::chrono::steady_clock::time_point next_check_at_{};
};

}  // namespace radar::processing
