/**
 * \file core/spoms/locationbackup.cpp
 * \date 16/02/2026
 * \author Aurélien Berthier, BENOIST Emile, TESSIER Dominique
 * \brief store alignment interpretations
 */


/*
 * PeptidOMS, Spectra to protein alignment tool
 * Copyright (C) 2026  Olivier Langella
 * <olivier.langella@cnrs.fr>
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "locationbackup.h"
#include "protein.h"
#include <QDebug>
#include <algorithm>
#include <pappsomspp/core/exception/exceptionnotimplemented.h>

namespace pappso
{
namespace spoms
{

LocationBackup::LocationBackup() : mp_protein(nullptr)
{
  start_line = 0;
  end_line   = 0;
  score      = 0;
  tree_id    = 0;
}

LocationBackup::LocationBackup(const pappso::spoms::Protein *protein_p,
                               int start_line_in,
                               int end_line_in,
                               int score_in,
                               int tree_id_in)
  : mp_protein(protein_p)
{
  start_line = start_line_in;
  end_line   = end_line_in;
  score      = score_in;
  tree_id    = tree_id_in;
}


LocationBackup::LocationBackup(const LocationBackup &other)
  : mp_protein(other.mp_protein)
{
  // qWarning() << "copy LocationBackup";
  //  throw pappso::ExceptionNotImplemented("no LocationBackup copy
  //  constructor");
  start_line = other.start_line;
  end_line   = other.end_line;
  score      = other.score;
  tree_id    = other.tree_id;
}

LocationBackup::~LocationBackup()
{
}

void
LocationBackup::update(int start_line_in,
                       int end_line_in,
                       int score_in,
                       int tree_id_in)
{
  start_line = start_line_in;
  end_line   = end_line_in;
  score      = score_in;
  tree_id    = tree_id_in;
}


QString
LocationBackup::toString() const
{
  return QString("[%1 ,%2], score : %3 , tree %4")
    .arg(start_line)
    .arg(end_line)
    .arg(score)
    .arg(tree_id);
}

QString
LocationBackup::getSubSequence() const
{
  QString sequence;
  auto sp_seq = mp_protein->getSubSequence(start_line, end_line);
  std::reverse(sp_seq.begin(), sp_seq.end());
  for(auto &spoms_aa : sp_seq)
    {
      sequence.append((char)spoms_aa.aa);
    }
  return sequence;
}
} // namespace spoms
} // namespace pappso
