/**
 * \file core/spoms/aaposition.h
 * \date 11/02/2026
 * \author Aurélien Berthier, BENOIST Emile, TESSIER Dominique
 * \brief handle processed spectrum
 */


/*
 * 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 <QString>
#include <QDebug>
#include <qcontainerfwd.h>
#include <qlogging.h>
#include "aaposition.h"
#include "spomsutils.h"

namespace pappso
{
namespace spoms
{


AAPosition::AAPosition()
{
}

AAPosition::~AAPosition()
{
}
AAPosition::AAPosition(int right_column_in,
                       int left_column_in,
                       int right_peak_in,
                       int left_peak_in,
                       double right_mass_in,
                       double left_mass_in)
{
  right_column = right_column_in;
  left_column  = left_column_in;
  right_peak   = right_peak_in;
  left_peak    = left_peak_in;
  right_mass   = right_mass_in;
  left_mass    = left_mass_in;
}

AAPosition::AAPosition(const AAPosition &other)
{
  // qWarning() << "copy AAPosition";
  right_column = other.right_column;
  left_column  = other.left_column;
  left_peak    = other.left_peak;
  right_peak   = other.right_peak;
  right_mass   = other.right_mass;
  left_mass    = other.left_mass;
  condition    = other.condition;
}
AAPosition &
AAPosition::operator=(const AAPosition &other)
{
  right_column = other.right_column;
  left_column  = other.left_column;
  left_peak    = other.left_peak;
  right_peak   = other.right_peak;
  right_mass   = other.right_mass;
  left_mass    = other.left_mass;
  condition    = other.condition;
  return *this;
}
int
AAPosition::getRightPeak() const
{
  return right_peak;
}

int
AAPosition::getLeftPeak() const
{
  return left_peak;
}


int
AAPosition::getRightColumn() const
{
  return right_column;
}


int
AAPosition::getLeftColumn() const
{
  return left_column;
}


std::uint32_t
AAPosition::getCondition() const
{
  return condition;
}

void
AAPosition::setCondition(std::uint32_t condition_in)
{
  if(condition_in == 0)
    {
      condition = 1;
    }
  else
    {
      condition = condition_in;
    }
}

void
AAPosition::updateColumn(const std::vector<int> &column_correspondance)
{
  right_column = column_correspondance[right_column] - 1;
  if(column_correspondance[left_column] != 0)
    {
      left_column = column_correspondance[left_column] - 2;
    }
  else
    {
      --left_column;
      while(column_correspondance[left_column] == 0)
        {
          --left_column;
        }
      left_column = column_correspondance[left_column] - 1;
    }
}

QString
AAPosition::toString() const
{
  if((condition & 1) == 1)
    {
      return "(" + SpomsUtils::massToString(left_mass) + " ," +
             SpomsUtils::massToString(right_mass) + ")" +
             QString::number(condition,
                             2); // " + Integer.toBinaryString(this.condition);
    }
  else
    {
      return "(" + SpomsUtils::massToString(left_mass) + " ," +
             SpomsUtils::massToString(right_mass) + ")*" +
             QString::number(condition,
                             2); // + Integer.toBinaryString(this.condition);
    }
}

double
AAPosition::getLeftMass() const
{
  return left_mass;
}
double
AAPosition::getRightMass() const
{
  return right_mass;
}

} // namespace spoms
} // namespace pappso
