/**
 * 列车信息推理结果转换引擎
 * */

#ifndef TRANSTRAINENGINE_H
#define TRANSTRAINENGINE_H

#include "AppCommon.h"
#include "MyYaml.h"
#include "EngineBase.h"
#include "EngineFactory.h"

class TransTrainEngine : public ai_matrix::EngineBase
{
public:
    TransTrainEngine();
    ~TransTrainEngine();

    APP_ERROR Init() override;
    APP_ERROR DeInit() override;
    APP_ERROR Process() override;

private:
    void InitParam();
    //校验车型是否符合验证
    bool AuthTransNum(int classId, const std::string &trainNum);
    //过滤第二步字段代号的误识别
    void FilterSingleData(std::vector<SingleData> &vecObjs, TargetMaxLen iMaxLen);
    //属性框内容转换
    void TransPro(TransSubData &transSubData, std::map<int, std::vector<SingleData>> &mapLine);
    //车号框内容转换
    void TransNum(TransSubData &transSubData, std::map<int, std::vector<SingleData>> &mapLine);
    //车头框内容转换
    void TransHead(TransSubData &transSubData, std::map<int, std::vector<SingleData>> &mapLine);

    void RecordNum(const TransSubData &transSubData, const std::shared_ptr<ProcessData> &pProcessData);

    bool SaveMiddleNumCsv(const std::vector<pair<string, uint32_t>> &vecNums, const std::shared_ptr<ProcessData> &pProcessData,
                          int iSourceId);
    //push数据到队列，队列满时则休眠一段时间再push
    void PushData(const std::string &strPort, const std::shared_ptr<ProcessData> &pProcessData);

    bool bUseEngine_;
    std::string strPort0_;
    ai_matrix::ModelConfig modelConfig_;
    std::string strResultPath_;
    std::vector<std::string> vecClassNames_;    // 分类名称集合

    std::map<int, bool> mapDataSourceIsEnd_;    //[key-数据源id, value-数据是否结束]

    std::map<int, std::map<std::string, uint32_t>> mapNumInfo_;
    std::map<int, uint32_t> mapPreFrameId_;
    int iSkipInterval_;

};

ENGINE_REGIST(TransTrainEngine)

#endif
