
/*******************************************************************************
 * Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
 *
 * This file is part of i2MassChroQ.
 *
 *     i2MassChroQ is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     i2MassChroQ is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with i2MassChroQ.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     Olivier Langella <olivier.langella@u-psud.fr> - initial API and
 *implementation
 ******************************************************************************/

#pragma once
#include <QString>
#include <QJsonObject>
#include <pappsomspp/core/precision.h>
#include <pappsomspp/core/trace/trace.h>
#include <qcbormap.h>
#include <qjsonobject.h>
#include <qjsonvalue.h>


namespace pappso
{
namespace spoms
{
class SpomsUtils
{

  protected:
  SpomsUtils()
  {
  }


  public:
  SpomsUtils(SpomsUtils &other)      = delete;
  void operator=(const SpomsUtils &) = delete;
  /**
   * This is the static method that controls the access to the singleton
   * instance. On the first run, it creates a singleton object and places it
   * into the static field. On subsequent runs, it returns the client existing
   * object stored in the static field.
   */

  static SpomsUtils *GetInstance();
  static const QString massToString(double mass);

  public:
  void setJsonParameters(const QJsonObject &json_params);
  const QJsonObject &getJsonParameters() const;

  /** @brief get JSON parameter value in the given section */
  QJsonValue getParameterValue(const QString &section,
                               const QString &name) const;

  /** @brief get JSON parameter value in the given section
   * switch to default boolean value if not found
   */
  bool getParameterValueOrDefault(const QString &section,
                                  const QString &name,
                                  bool bool_default_value) const;

  /** @brief get JSON parameter value in the given section
   * switch to default integer value if not found
   */
  int getParameterValueOrDefault(const QString &section,
                                 const QString &name,
                                 int int_default_value) const;

  void setParameterValue(const QString &section,
                         const QString &name,
                         bool true_or_false);
  void
  setParameterValue(const QString &section, const QString &name, int number);


  void
  setParameterValue(const QString &section, const QString &name, double number);

  double getMs2Accuracy() const;

  int getRealTimeSave() const;
  int getNbMinAaFound() const;

  int getInitialisationScorePost();
  int getInitialisationScoreMain();

  pappso::PrecisionPtr getFragmentTolerance() const;


  const QJsonObject getAlignmentScoreGrid() const;
  const QJsonObject getPostTreatmentScoreGrid() const;


  QCborMap getMassSpectrumCborMap(const pappso::Trace &mass_spectrum) const;


  private:
  const QJsonObject getDefaultParameterObject(const QString &section,
                                              const QString &name) const;


  private:
  static SpomsUtils *mp_spomsUtils;

  QJsonObject m_spomsParameters;
  pappso::PrecisionPtr m_fragmentTolerance;
  double m_ms2accuracy          = 0.02;
  int m_initialisationScorePost = -1;
  int m_initialisationScoreMain = -1;
};
} // namespace spoms
} // namespace pappso
