// 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
{


class DECLSPEC HighResPeakPicker
{

  public:
  struct Parameters
  {
    double signalToNoise       = 0.8;
    qsizetype missingPeakCount = 0;
    double minimumIntensity    = 0.0;

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

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

    Parameters &
    operator=(const Parameters &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;
    }
  };

  HighResPeakPicker();

  explicit HighResPeakPicker(
    Parameters &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:
  Parameters m_parameters;
  LocalSignalToNoiseEstimator::Parameters m_localSignalToNoiseEstimatorParams;
};


} // namespace libXpertMassCore
} // namespace MsXpS
