// Copyright 2026 Filippo Rusconi
// Inspired by code in OpenMS, by Lars Nilse

#pragma once

/////////////////////// stdlib includes


/////////////////////// Qt includes
#include <QList>
#include <QMap>

/////////////////////// pappsomspp includes
#include "pappsomspp/core/trace/trace.h"


/////////////////////// Local includes
#include "MsXpS/export-import-config.h"
#include "MsXpS/libXpertMassCore/Processing/LocalSignalToNoiseEstimator.hpp"

namespace MsXpS
{
namespace libXpertMassCore
{
namespace Processing
{


struct HighResPeakPickerParameters
{
  double signalToNoise       = 0.8;
  qsizetype missingPeakCount = 0;
  double minimumIntensity    = 0.0;

  HighResPeakPickerParameters()
    : signalToNoise(0.8), missingPeakCount(0), minimumIntensity(0) {};

  HighResPeakPickerParameters(const HighResPeakPickerParameters &other)
    : signalToNoise(other.signalToNoise),
      missingPeakCount(other.missingPeakCount),
      minimumIntensity(other.minimumIntensity)
  {
  }

  HighResPeakPickerParameters &
  operator=(const HighResPeakPickerParameters &other)
  {
    if(&other == this)
      return *this;

    signalToNoise    = other.signalToNoise;
    missingPeakCount = other.missingPeakCount;
    minimumIntensity = other.minimumIntensity;

    return *this;
  }

  QString
  toString() const
  {
    QString text = "HighResPeakPicker parameters:\n";

    text +=
      QString(
        "signalToNoise: %1\nmissingPeakCount: %2\nminimumIntensity: %3\n\n")
        .arg(signalToNoise)
        .arg(missingPeakCount)
        .arg(minimumIntensity);

    return text;
  }
};

class DECLSPEC HighResPeakPicker
{

  public:
  HighResPeakPicker();

  explicit HighResPeakPicker(
    HighResPeakPickerParameters &parameters,
    LocalSignalToNoiseEstimator::Parameters signal_to_noise_estimator_params);

  virtual ~HighResPeakPicker();

  void setLocalSignalToNoiseEstimatorParams(
    const LocalSignalToNoiseEstimator::Parameters &params);
  HighResPeakPicker &operator=(const HighResPeakPicker &other);

  struct PeakRange
  {
    double mzStart;
    double mzStop;
  };

  void pick(const pappso::Trace &initial_trace,
            pappso::Trace &picked_peaks,
            QList<PeakRange> &peak_ranges);

  protected:
  HighResPeakPickerParameters m_parameters;
  LocalSignalToNoiseEstimator::Parameters m_localSignalToNoiseEstimatorParams;
};


} // namespace Processing
} // namespace libXpertMassCore
} // namespace MsXpS
