// VisionMultiUnitResult.h: interface for the CVisionMultiUnitResult class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include "VisionUnitResult.h"

#ifdef BUILD_COMMDLL
#define COMMDLL_DLLCLASS __declspec(dllexport)
#else
#define COMMDLL_DLLCLASS __declspec(dllimport)
#endif

class COMMDLL_DLLCLASS CVisionMultiUnitResult
{
public:
    CVisionMultiUnitResult(int nNofOfUnits = 1);
    virtual ~CVisionMultiUnitResult();

    void InitParameters(int nNoOfUnits, const std::vector<int>& pnTotalGx, const std::vector<int>& pnTotalLx, const std::vector<int>& pnDataSetType, int nNoOfResultCat = 1);

    void SetTeachMode(int nUnitNo, bool bState, int nCategory = 0);
    bool IsTeachMode(int nUnitNo, int nCategory = 0);

    void SetImageTaken(int nUnitNo, bool bState, int nCategory = 0);
    bool IsImageTaken(int nUnitNo, int nCategory = 0);

    void SetResultReady(int nUnitNo, bool bState, int nCategory = 0);
    bool IsResultReady(int nUnitNo, int nCategory = 0);

    std::string GetDecodedString(int nUnitNo, int nGx = 0, int nLx = 0, int nCategory = 0);
    void SetDecodedString(int nUnitNo, std::string csDecodedString, int nGx = 0, int nLx = 0, int nCategory = 0);

    void SetResultCode(int nUnitNo, std::string csResultCode, int nCat = 0);
    std::string GetResultCode(int nUnitNo, int nCat = 0);

    void GetResultParams(int nUnitNo, std::vector<double>& vecResultParam, int nGx = 0, int nLx = 0, int nCategory = 0);
    double GetResultParams(int nUnitNo, int nParamNo, int nGx = 0, int nLx = 0, int nCategory = 0);
    void SetResultParams(int nUnitNo, int nParamNo, double dResult, int nGx = 0, int nLx = 0, int nCategory = 0);

    double GetPviParams(int nUnitNo, int nParamNo, int nGx = 0, int nLx = 0, int nCategory = 0);
    void SetPviParams(int nUnitNo, int nParamNo, double dResult, int nGx = 0, int nLx = 0, int nCategory = 0);

    CVisionUnitResult* GetUnitResultPtr(int nUnitNo, int nCategory = 0);
    int GetDataSetTypeIndex(int nDataSetType);

    int GetTotalUnits();
    int GetNoOfResultCat();
    void GetSettings(int& nNoOfUnits, int& nNoOfResultCat);
    void SetUnitResult(int nUnitNo, int nCat, CVisionUnitResult& visionUnitResult);
    void GetUnitResult(int nUnitNo, int nCat, CVisionUnitResult& visionUnitResult);

    void ResetAll(std::string csResultCode = _T("."), std::string csDecodedString = _T(""));
    CVisionMultiUnitResult& operator=(const CVisionMultiUnitResult& visionMultiUnitResult);

    void SetOtfSOSAck(bool bState);
    bool IsOtfSOSAck();
    bool IsValidUnit(int nUnitNo, int nCategory = 0);
    bool IsLastUnit(int nUnitNo, int nCategory = 0);

    bool IsUnitResultValid(int nUnitNo);
    void SetUnitResultValid(int nUnitNo, bool bState);

    // For debug
    void TraceResult();

private:
    // Methods

    void ReleaseBuffer();

    void InitBuffer(std::vector<CVisionUnitResult>& pVisionUnitResult, int nTotalGx = 1, int nTotalLx = 1);
    bool IsSameDataSetType(const std::vector<int>& pnDataSetType, int nNoOfResultCat);
    bool IsSameGxLx(const std::vector<int>& pnTotalGx, const std::vector<int>& pnTotalLx, int nNoOfResultCat);

    // Attributes
    int m_nNoOfUnits;
    bool m_bOtfSOSAck;

    //
    std::vector<std::vector<CVisionUnitResult>> m_ppVisionUnitResultCat;
    int m_nNoOfResultCat;
    int m_nLastCategory;
    std::vector<int> m_pnTotalGx;
    std::vector<int> m_pnTotalLx;
    std::vector<int> m_pnDataSetType;
};
