#ifndef XLSXHANDLER_H
#define XLSXHANDLER_H

#include <QtCore>

#include "xlsxdocument.h"
#include "protocol.h"
#include "global.h"

namespace XlsxHandler {
    void test();
    /**
     * @brief readFile
     * @param filePath
     * @return
     * 0:Succ;
     * 1:File not existed;
     * 2:File not xlsx;
     * 3:Sheet is empty.
     */
    QXlsx::Document* openXlsxFile(const QString& sourceFilePath);
    // read.
    int readFile(const QString filePath,Global::CurveFileData&);
    void readPhaseData(QXlsx::Worksheet*,int& startLineIndex,Global::PhaseTotalInfo&);
    void readAnalysisOperation(QXlsx::Worksheet*,int& startLineIndex,Global::CurveFileData&);

    double getCellDoubleValue(QXlsx::Worksheet* workSheet, int row, int col, double defaultValue = 0.0);
    int getCellIntValue(QXlsx::Worksheet* workSheet, int row, int col, int defaultValue = 0);
    QString getCellStringValue(QXlsx::Worksheet* workSheet, int row, int col, const QString& defaultValue = "");

    // write.
    void writeExperimentFile(const QString filePath);

    void writeXlsxFile(const QString filePath);
    void writeSmoothnessFile(const QString filePath);
    void xlsxFileAppendAnalysisOperation(const QString filePath);

    void writeAnalysisOperationDetail(QXlsx::Document*doc,const int row);

    // discard
    int deleteInvalidRow(QXlsx::Document*doc);

    extern QString _currentFilePath;

    const QString ConUnitMg = "mg";
    const QString ConUnitDegreeCentigrade = "℃";
    const QString ConUnitDegreeCentigradePerMin = "℃/min";
    const QString ConUnitMin = "min";

    const QString ConFileDataInfo = "文件数据信息";
    const QString ConSampleName = "样品名称：";
    const QString ConSampleWeight = "样品质量：";
    const QString ConCrucibleWeight = "坩埚质量：";
    const QString Conexperimenter = "实验人员：";
    const QString ConDate = "实验日期：";
    const QString ConMeasureType = "测量类型：";
    const QString ConPhaseSize = "阶段数量：";

    const QString ConPhaseProfix = "#";
    const QString ConPhaseHeaderTime = "Time/min";
    const QString ConPhaseHeaderTemp = "Temp/℃";
    const QString ConPhaseHeaderVoltage = "Voltage/mW";

    const QString ConPhaseIndex = "阶段索引：";
    const QString ConPhaseCutoffTemp = "截止温度：";
    const QString ConPhaseHeatingRate = "升温速率：";
    const QString ConPhaseConstantTempTime = "恒温时间：";
    const QString ConPhaseAtmosphere = "气氛：";
    const QString ConPhaseDataSize = "数据个数：";

    const QString ConAnalysisOperationCount = "AnalysisOperationCount";
}

#endif // XLSX_H
