//---------------------------------------------------------------------------

#ifndef CDSVmsCtlrFH
#define CDSVmsCtlrFH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <stdio.h>
#include <ADODB.hpp>
#include <DB.hpp>
#include "ITSLibF.h"
#include "ITSDbF.h"
#include "CDSObjectF.h"
//---------------------------------------------------------------------------
#include "CenterCommF.h"
//---------------------------------------------------------------------------

typedef enum enVmsState
{
    state_normal = 0,
    state_error,
    state_module,
} EN_VMS_STATE;
//---------------------------------------------------------------------------

typedef enum _e_schedule_mode
{
    enScheduleAuto,
    enScheduleFix,
    enScheduleBase,
    enScheduleMax,
} e_schedule_mode;
//---------------------------------------------------------------------------
typedef enum _e_form_type
{
    eFormTp_traf_1   = 11,  //	소통상황(1단)
    eFormTp_traf_2   = 12,  //	소통상황(2단)
    eFormTp_traf_3   = 13,  //	소통상황(3단)
    eFormTp_traf_4   = 14,  //	소통상황(4단)
    eFormtp_figure   = 15,  //	소통상황(도형식배경소통정보)
    eFormTp_congest  = 16,  //	정체소통상황
    eFormTp_incident = 20,  //	돌발문안
    eFormTp_gongsa   = 30,  //	공사/행사문안
    eFormTp_hongbo   = 40,  //	홍보문안
    eFormTp_deture   = 50,  //	우회도로
    eFormTp_safe     = 60,  //	재난안전
    eFormTp_video    = 70,  //	동영상
    eFormTp_stream   = 80,  //	스트리밍영상
    eFormTp_atmp     = 90,  //	대기환경
    eFormTp_park     = 91,  //	주차정보
} e_form_type;

typedef enum _e_schedule_type
{
    eSchTp_traffic  = 0,    //0:교통,
    eSchTp_incident = 1,    //1:돌발,
    eSchTp_gongsa   = 2,    //2:공사행사,
    eSchTp_hongbo   = 3,    //3:홍보,
    eSchTp_deture   = 4,    //4:우회,
    eSchTp_congest  = 5,    //5:정체,
    eSchTp_safe     = 6,    //6:안전,
    eSchTp_video    = 7,    //7:동영상,
    eSchTp_stream   = 8,    //8:스트리밍영상
    eSchTp_atmp     = 9,    //9:대기환경
    eSchTp_park     = 10,   //10:주차정보
    eSchTp_max,
} e_schedule_type;
//---------------------------------------------------------------------------

typedef struct tagScheduleUsage
{
    int Total[eSchTp_max];
    int Use[eSchTp_max];
} SCHEDULE_USAGE, *PSCHEDULE_USAGE;

//---------------------------------------------------------------------------
class TVmsIfscRltn
{
public:
    TVmsIfscRltn();
    ~TVmsIfscRltn();
public:
    String  VMS_CTLR_NMBR;  //NUMBER(10)	N			VMS 제어기 번호
    int     VMS_IFSC_ID;    //NUMBER(10)	N			VMS 정보제공구간 ID
    int     DSPL_PRRT;      //NUMBER(2)	    Y			표출 우선순위
    String  CNGS_CNFM_YN;   //CHAR(1)	Y	'Y'		정체폼 정체판정 여부
    int     CNGS_CNFM_SPED; //NUMBER(2)	Y	5		정체폼 정체판정 속도
};
//---------------------------------------------------------------------------

typedef struct tagVmsPhase
{
    int                 DSPL_HH;    //표출시간
    String              DNLD_YN;    //다운로드성공여부
    String              DSPL_CD;    //표출방법
    int                 VMS_SCH_FORM_TYPE;
    String              VMS_DSPL_MSG_TXT;
    Graphics::TBitmap  *pVmsBmp;    //표출메시지(Bitmap 이미지)
} VMS_PHASE;

class TVmsMsg
{
public:
    TVmsMsg();
    ~TVmsMsg();

public:
    void Init();

    int         Total;      //전체메시지 갯수
    int         Curr;       //현재표출갯수(사용안함)
    String      OFFER_DT;   //제공시각
    bool        OFFER_YN;   //정시제공여부(true:정시제공,false:5분이상이전제공데이터)
    VMS_PHASE   PHASE[INT_VMS_MAX_FORM];
};

//---------------------------------------------------------------------------

class TVmsCtlr : public TCDSObject
{
public:
    TVmsCtlr();
    ~TVmsCtlr();

public:
    String  WEB_CMRA_IP;            //	N	VARCHAR2(20)	Y			웹 카메라 아이피
    String  WEB_CMRA_PORT;          //	N	NUMBER(5)	    Y			웹카메라 포트
    String  WEB_CMRA_ID;            //	N	VARCHAR2(20)	Y			웹카메라 ID
    String  WEB_CMRA_PWD;           //	N	VARCHAR2(20)	Y			웹카메라 비밀번호
    String  STRM_SESN_NM;           //	N	VARCHAR2(200)	Y			스트리밍 세션 명
    String  OPER_MODE;              //	N	VARCHAR2(7)	    Y	'A'		운영 모드
    int     VMS_MAX_PHSE_NUM;       //	N	NUMBER(2)	    Y	14		VMS 최대 표출면 개수
    int     DEF_PHSE_CHNG_CYCL;     //	N	NUMBER(3)	    Y	5		기본메시지주기
    String  PANL_ON_TIME;           //	N	VARCHAR2(4)	    Y	'0400'	전광판 ON TIME
    String  PANL_OFF_TIME;          //	N	VARCHAR2(4)	    Y	'0200'	전광판 OFF TIME
    int     PANL_PWER_MODE;         //	N	NUMBER(3)	Y	2		전광판 전원 모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
    int     FAN_MODE;               //	N	NUMBER(3)	Y	2		FAN 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
    int     FAN_RUN_TMPR;           //	N	NUMBER(3)	Y	30		팬 동작 온도
    int     HETR_MODE;              //	N	NUMBER(3)	Y	2		히터 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
    int     HETR_RUN_TMPR;          //	N	NUMBER(3)	Y	0		히터 동작 온도
    int     BRGH_MODE;              //	N	NUMBER(3)	Y	2		휘도 모드(0x00:주간,0x01:야간,0x00:자동,0x09:알수없음)
    int     BRGH_CURR_STEP;         //	N	NUMBER(3)	Y	40		휘도 현재 단계(0~100)
    int     BRGH_WEEK_STEP;         //	N	NUMBER(3)	Y	64		휘도 주간 단계(0~100)
    int     BRGH_NGHT_STEP;         //	N	NUMBER(3)	Y	48		휘도 야간 단계(0~100)
    int     MODL_ERR_RATE;          //	N	NUMBER(3)	Y	10		VMS 모듈 오류 율
    int     CMNC_FAIL_RATE;         //	N	NUMBER(3)	Y	60		VMS 통신 오류 기본 값
    String  WEB_CMRA_CMPY;          //	N	VARCHAR2(50)	Y			웹카메라제조사(삼성카메라'Samsung')
    String  WEB_CMRA_MDL;           //	N	VARCHAR2(126)	Y			웹카메라모델

    String  ParamResTime;

    String  VMS_TYPE_NM;

    //크기
    int     WIDTH, HEIGHT;
    int     ROW_NUM, COL_NUM;
    int     MODL_ROW_NUM, MODL_COL_NUM;
    int     POWR_ROW_NUM, POWR_COL_NUM;

    SCHEDULE_USAGE  FormCnt[enScheduleMax];

    TVmsMsg *VmsMsg;

    INT_VMS_STATE   STATE;
    int             RunState;

public:

    void InitFormCount()
    {
        for (int ii = 0; ii < eSchTp_max; ii++)
        {
            for (int jj = 0; jj < enScheduleMax; jj++)
            {
                FormCnt[jj].Total[ii] = 0;
                FormCnt[jj].Use[ii]   = 0;
            }
        }
    };
    void CheckRunState();
    TItsMap<int, TVmsIfscRltn*>  FIfscRltn;

public:
    __property String  VMS_CTLR_NMBR     = { read = CTLR_NMBR,     write = CTLR_NMBR     };
    __property String  VMS_CTLR_ID       = { read = CTLR_ID,       write = CTLR_ID       };
    __property String  VMS_NM            = { read = NAME,          write = NAME          };
    __property String  VMS_CTLR_IP       = { read = CTLR_IP,       write = CTLR_IP       };
    __property int     VMS_CTLR_PORT     = { read = CTLR_PORT,     write = CTLR_PORT     };
    __property int     VMS_CTLR_LOCAL_NO = { read = CTLR_LOCAL_NO, write = CTLR_LOCAL_NO };
    __property String  VMS_TYPE_CD       = { read = TYPE_CD,       write = TYPE_CD       };
};
//---------------------------------------------------------------------------
typedef std::map<String, TVmsCtlr*>::iterator   VmsIterator;
//---------------------------------------------------------------------------

class TVmsSize
{
public:	// User declarations
    String TypeCd;
    String TypeNm;
    int    Width;
    int    Height;

public:		// User declarations
    TVmsSize();
};

//---------------------------------------------------------------------------
class TVmsCtlrManager
{
public:
    TVmsCtlrManager();
    ~TVmsCtlrManager();

private:
	TStream *FImgStream;

public:
    TItsMap<String, TVmsSize*> FVmsSize;
    TItsMap<String, TVmsCtlr*> FLists;

    void InitFormCount();

    int  FMinWidth, FMinHeight;
    int  FMaxWidth, FMaxHeight;
public:
    bool LoadVmsSize(TADOConnection *ADbConn=NULL);
    bool LoadFromDb(TADOConnection *ADbConn=NULL);
    bool LoadStatusFromDb(TADOConnection *ADbConn=NULL);
    bool DeleteVms(TVmsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool InsertVms(TVmsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool UpdateVms(TVmsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeVms(TVmsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeFcltInfo(TVmsCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool GetNextVmsId(int &ANmbr, int &AId, TADOConnection *ADbConn=NULL);

    bool UpdateCtlrInfo(TVmsCtlr *AObj, TADOConnection *ADbConn=NULL);

    bool UpdateIfscCngsSpeedInfo(int ACngsSpd, TADOConnection *ADbConn=NULL);
    bool LoadIfscRltn(TADOConnection *ADbConn=NULL);
    bool SaveIfscRltn(TVmsCtlr *AObj, TADOConnection *ADbConn=NULL);

    bool LoadVmsMsg(TADOConnection *ADbConn=NULL);

    bool LoadVmsFormUsage(TADOConnection *ADbConn=NULL);

    bool InsVmsControlHs(String ACtlDt, String AVmsNmbr, String ACtlType, String ACtlVal, String ACtlRes, String AUserId, TADOConnection *ADbConn=NULL);
};
//---------------------------------------------------------------------------
extern TVmsCtlrManager *VmsCtlrManager;
//---------------------------------------------------------------------------
void VmsInitStatus(INT_VMS_STATE *AState);
int  VmsGetFormTypeIdx(int AFormType);
//---------------------------------------------------------------------------

#endif
