/**
 * \file output/jsonexport.cpp
 * \date 29/05/2026
 * \author Olivier Langella
 * \brief JSON PSM export
 */


/*
 * SpecGlobTool, Spectra to peptide alignment tool
 * Copyright (C) 2023  Olivier Langella
 * <olivier.langella@universite-paris-saclay.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 "jsonexport.h"


JsonExport::JsonExport(pappso::cbor::JsonStreamWriter *json_output_p)
  : pappso::cbor::psm::PsmCbor2Json(json_output_p)
{
}

JsonExport::~JsonExport()
{
}


void
JsonExport::setOnlyScanNativeIdList(const QStringList &native_id_list)
{
  m_onlyExportScanIdList = native_id_list;
}

void
JsonExport::scanStarted(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
  m_skipScan = false;
  if(m_onlyExportScanIdList.isEmpty())
    {
      pappso::cbor::psm::PsmCbor2Json::scanStarted(monitor);
    }
  else
    {
      QString native_id = m_cborScanId.value("native_id").toString();
      if(m_onlyExportScanIdList.contains(native_id))
        {
          pappso::cbor::psm::PsmCbor2Json::scanStarted(monitor);
        }
      else
        {
          m_skipScan = true;
        }
    }
}

void
JsonExport::scanFinished(pappso::UiMonitorInterface &monitor [[maybe_unused]])
{
  if(!m_skipScan)
    {
      mp_jsonOutput->endArray(); // psm_list
      mp_jsonOutput->endMap();   // scan
    }
}

void
JsonExport::psmReady(pappso::UiMonitorInterface &monitor)
{
  if(!m_skipScan)
    {
      pappso::cbor::psm::PsmCbor2Json::psmReady(monitor);
    }
}
