#include "base_utility.hh"
#include <QFileInfo>
#include <QDir>
#include <cassert>

QString createOutputPrefix(ChartScale scale, CurrencyPair pair)
{
    QString prefix;
    prefix += chartScaleToString(scale);
    prefix += "_";
    prefix += currencyPairToString(pair);
    prefix += '_';
    return prefix;
}

QString createOutputPrefix(const CandleChartModel& model)
{
    return createOutputPrefix(model.chartScale(), model.currencyPair());
}

QString outputFileName(
    const QString& folder, const QString& prefix,
    const QDateTime& time, const QString& suffix)
{
    QString name = prefix;
    name += time.toString("yyyy-MM-dd_HH-mm");
    name += suffix;
    QFileInfo info(QDir(folder), name);
    return info.absoluteFilePath();
}

QString outputFileName(
    const QString& folder, const CandleChartModel& model, const QString& suffix)
{
    assert(!model.isEmpty());
    QString prefix = createOutputPrefix(model);
    QDateTime first = model.cbegin().value().dateTime();
    return outputFileName(folder, prefix, first, suffix);
}

