#pragma once

#include <string>
#include <unordered_map>
#include <vector>

#include "shared_types.hpp"

namespace radar::preprocessing {

class CalibrationMaster;

class ReferenceMaster {
  public:
    // Loads a serialized raw sweep bundle with one reference trace per combo.
    void load_bundle(const std::string& path);
    // Builds calibrated references in memory using currently loaded raw references.
    // Must be called after load_bundle() and after calibration standards are loaded.
    void prepare_calibrated(const CalibrationMaster& calibration_master);
    // Ensures all runtime combos are present in loaded references.
    void validate_combos(const std::vector<ipc::ComboKey>& combos) const;
    // Subtracts per-combo reference trace from calibrated trace.
    [[nodiscard]] auto apply(const ipc::SweepTraceBlock& calibrated_trace) const -> ipc::SweepTraceBlock;

  private:
    std::unordered_map<ipc::ComboKey, ipc::SweepTraceBlock, ipc::ComboKeyHash> raw_references_by_combo_{};
    std::unordered_map<ipc::ComboKey, ipc::SweepTraceBlock, ipc::ComboKeyHash> calibrated_references_by_combo_{};
};

}  // namespace radar::preprocessing
