#ifndef FORMATCONVERTOR_H
#define FORMATCONVERTOR_H

#include "candle_chart_model.hh"
#include <QString>

/**
 * @brief Default input format used by convertor (%e for datetime)
 */
constexpr char defaultFormat[] = "%d(yyyy.MM.dd), %t(hh:mm), %o, %h, %l, %c, %v";

/**
 * @brief Default value separator used by convertor
 */
constexpr char defaultSeparator[] = ",";

/**
 * @brief Type of value in data file line
 */
enum class ValueType
{
    Date,
    Time,
    DateTime,
    Open,
    High,
    Low,
    Close,
    Volume
};

class ChartCandle;
class QFile;

/**
 * @brief Convert input file to output file(s) in format used in trading tools
 */
class FormatConvertor
{
    public:
        FormatConvertor();
        void inputFile(const QString& file);
        void inputFormat(const QString& format);
        void outputFolder(const QString& folder);
        void outputPrefix(const QString& prefix);
        void outputSufix(const QString& sufix);
        void currencyPair(CurrencyPair pair);
        void chartScale(ChartScale scale);
        void splitPeriod(ChartScale period);
        bool convert(QString& error);

    private:
        bool parseFormat(QString& error);
        ChartCandle parseCandle(QFile& file, ChartCandle& lastCandle);
        bool parseLine(const QString& line, ChartCandle& data);
        bool processFile(QString& error);

    private:
        QString inputFile_;
        QString inputFormat_;
        QString inputSeparator_;
        QString outputFolder_;
        QString outputPrefix_;
        QString outputSufix_;
        CurrencyPair currencyPair_;
        ChartScale chartScale_;
        ChartScale splitPeriod_;

    private:
        QString timeFormat_;
        QString dateFormat_;
        QString dateTimeFormat_;
        QList<ValueType> valueType_;
};

#endif // FORMATCONVERTOR_H
