/*============================================================
/   COPYRIGHT: JDSU T&M PTE LTD
/   Filename    : kpi_csv.h
/   Description: This class is the parent class for all kinds
/                of CSV output
/
/=============================================================
*/

#ifndef XTREME_KPI_AGENT_INTERNAL_KPI_CSV_H_
#define XTREME_KPI_AGENT_INTERNAL_KPI_CSV_H_

#include "xtreme/kpi_agent/internal/kpi_common_includes.h"
#include <fstream>  // NOLINT[readability/streams]
#include <string>

namespace xtreme {
namespace usart {
// This will be used in later stages
#if 1
typedef struct {
    // Common
    bool    bKpiSchedulerEnabled;
#if 0
    time_t  tKpiSchedulerSTime;
    time_t  tKpiSchedulerETime;
#endif
    int nCsvInt;  // When specified time(Sec) passed, new file will create
    int nIntInt;  // Integration interval
    // Integration Interval Start Timestamp
    pl_TimeStampType tIntegrationStartTS;
    // Integration Interval End Timestamp
    pl_TimeStampType tIntegrationEndTS;

    uint8_t nKpiCsvType;  // CSV types

    // CSV file for TTR
    std::string sTTRCsvFileName;
}KPI_CSV_INFO;
#endif

class CKPICsv {
 public:
    explicit CKPICsv(const std::string& appn_name);
    virtual ~CKPICsv();
 public:
    KPI_CSV_INFO *m_pCsvInfo;
    tbb::atomic<uint64_t> m_csv_rows;
 public:
    virtual void BeginCsv(KPI_CSV_INFO *pInfo)=0;
    /* virtual void OutputCsv(CKpiNode* pKpiNode, 
       double dValue, bool bIsNull=FALSE)=0;*/
    // virtual void OutputCsv(double dValue, bool bIsNull = false) = 0;
    // For BS1
    virtual int OutputCsv(const EventPtr &p_event, const xtreme::Timestamp &start_time,
        const xtreme::Timestamp &end_time);
    virtual void EndCsv();
 public:
    bool MakeSurePathExists(const char *iPath);
    bool GetLatestCsvFileName(const std::string& sSerialName,
                              std::string sCsvName
                              /*tm* pTMLastCsvTime=NULL*/);
    virtual void ClearData() {}

 protected:
    std::ofstream m_fCsv;
    std::string m_appn_name;
    std::string start_time_str_;
    std::string end_time_str_;
};

} }  // namespace xtreme::usart

#endif  // XTREME_KPI_AGENT_INTERNAL_KPI_CSV_H_
