// bytran -|- spectral calculations for portable devices using the HITRAN database
//
// Developed by Dzianis Pliutau (Denis Plutov) and Kostya Roslyakov
// www.bytran.org | bytran@bytran.org
// Copyright (c) 2016 Dzianis Pliutau
// Distributed under the MIT license
//
// The MIT License (MIT)
// Copyright (c) 2016 Dzianis Pliutau
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



// Object is used to handle the access and manimulation of the downlaod history file
// This approach is not currently in use and has known errors in the algorithm (does not work in all cases), not well structured
#ifndef DOWNLOADREGIONSFINDER_H
#define DOWNLOADREGIONSFINDER_H

#include <QVector>
#include <QString>
#include <QFile>

class DownloadRegionsFinder
{
public:

    DownloadRegionsFinder();

    // Method to read the download history data from file
    void readDownloadHistoryFile();

    // Name of the file containing the history of downloads
    QString getDownloadHistoryFilePath();
    void setDownloadHistoryFilePath(QString newDownloadHistoryFilePath);

    // Methods to get and set the user specified and determined for the new download spectral region
    double getStartWn();
    void setStartWn(double newStartWn);
    double getEndWn();
    void setEndWn(double newEndWn);

    // Getting and setting the download regions wavelength arrays (start and end)
    QVector<double> *getDownloadStartWn();
    void setDownloadStartWn(QVector<double> *newDownloadStartWn);
    QVector<double> *getDownloadEndWn();
    void setDownloadEndWn(QVector<double> *newDownloadEndWn);

    // Methods to get and set the update history file very start and very end wavenumber values
    double getUpdatedHistoryFileStartWn();
    void setUpdatedStartWn(double newUpdatedHistoryFileStartWn);
    double getUpdatedHistoryFileEndWn();
    void setUpdatedEndWn(double newUpdatedHistoryFileEndWn);

    // Methods to get and set the download regions at a specified index
    double getDownloadStartWnValueAtIndex(int index);
    void setDownloadStartWnValueAtIndex(int index, double value);
    double getDownloadEndWnValueAtIndex(int index);
    void setDownloadEndWnValueAtIndex(int index, double value);

    // Array with the new wavenumbers for the new updated download history file
    int getIndexStartWnInHistory();  // Starting index for the new download region determined from the history file data
    void setIndexStartWnInHistory(int newIndexStartWnInHistory);
    int getIndexEndWnInHistory();    // Ending index for the new download region determined from the history file data
    void setIndexEndWnInHistory(int newIndexEndWnInHistory);

    // Very beginning wavenumber for the spectral regions to download
    double getDownloadVeryStartWn();
    // Very end wavenumber for the spectral regions to download
    double getDownloadVeryEndWn();

    // Method to determine the new download region based on the requested region and the data about the spectral ranges already downloaded
    void findDownloadRegions();

    // Method to update the download history file
    void updateDownloadHistoryFile();

private:

    // Arrays with the information on the history of the downloaded beginning and ending wavenumbers
    QVector<double> historyStartWn;  // Array with the history of start values of the downloaded regions
    QVector<double> historyEndWn;    // Array with the history of end values of the downloaded regions

    // Array with the wavenumbers for the new download region
    QVector<double> downloadStartWn;
    QVector<double> downloadEndWn;

    // Indexes of wavenumber boundaries as determined from the old
    int indexStartWnInHistory;  // Starting index for the new download region determined from the history file data
    int indexEndWnInHistory;    // Ending index for the new download region determined from the history file data

    // Name of the file containing the history of downloads
    QString downloadHistoryFilePath;

    // Variables containing the user set download region boundaries as well as those determined after adjusting the download region based on the download history file information
    double startWn;
    double endWn;

    // Very start and very end download regions wavelengths (determined by comparing with the history download file)
    double downloadVeryStartWn;  // Very beginning wavenumber for the spectral regions to download
    double downloadVeryEndWn;    // Very end wavenumber for the spectral regions to download

};

#endif // DOWNLOADREGIONSFINDER_H
