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

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

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

class TCctvPset
{
public:
    TCctvPset()
    {
        PSET_NMBR = 1;
        PSET_NM   = "";
        PAN       = 0;
        TILT      = 0;
        ZOOM      = 0;
        FOCS      = 0;
        ANGLE     = 0;
        DFLT_YN   = "N";
    };
    ~TCctvPset() {};

private:

public:
    String  CCTV_CTLR_NMBR;     //	N	NUMBER(10)	    N			CCTV 제어기 번호
    int     PSET_NMBR;          //	N	NUMBER(4)	    N			프리셋 번호
    String  PSET_NM;            //	N	VARCHAR2(100)	N			프리셋 명
    int     PAN;                //	N	NUMBER(4)	    Y	0		팬 값
    int     TILT;               //	N	NUMBER(4)	    Y	0		틸트 값
    int     ZOOM;               //	N	NUMBER(4)	    Y	0		줌 값
    int     FOCS;               //	N	NUMBER(4)	    Y	0		포커스 값
    int     ANGLE;              //	N	NUMBER(4)	    Y	0		각도 값
    String  DFLT_YN;            //	N	CHAR(1)	        Y	'N'		디폴트 여부

public:
    String  DEL_YN;

};

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

public:
    String  CCTV_CAPT_IP;       //	N	VARCHAR2(20)	Y			CCTV 자막기 아이피
    String  CCTV_CAPT_PORT;     //	N	VARCHAR2(5)	    Y			CCTV 자막기 포트
    String  CCTV_FIBR_IP;       //	N	VARCHAR2(20)	Y			CCTV 광장비 아이피
    String  CCTV_ENCD_IP;       //	N	VARCHAR2(20)	Y			CCTV 인코더 아이피
    String  STRM_SVR_IP;        //	N	VARCHAR2(20)	Y			스트리밍 서버 아이피
    String  STRM_SVR_PORT;      //	N	VARCHAR2(5)	    Y			스트리밍 서버 포트
    String  STRM_SESN_NM;       //	N	VARCHAR2(200)	Y			스트리밍 세션 명
    String  STRM_STOR_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 저장 주소
    String  STRM_RTSP_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 RTSP 주소
    String  STRM_RTMP_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 RTMP 주소
    String  STRM_HTTP_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 HTTP 주소
    String  INTR_RTSP_ADDR;     //	N	VARCHAR2(200)	Y			내부 RTSP 주소
    String  INTR_RTMP_ADDR;     //	N	VARCHAR2(200)	Y			내부 RTMP 주소
    String  INTR_HTTP_ADDR;     //	N	VARCHAR2(200)	Y			내부 HTTP 주소
    String  CCTV_SBST_IMGN;     //	N	BLOB	        Y			CCTV 대체 영상
    String  CCTV_SBST_DSPL_YN;  //	N	CHAR(1)	        Y	'N'		CCTV 대체 표출 여부
    String  SYOP_CNTL_YN;       //	N	CHAR(1)	        Y	'N'		운영자 제어 여부
    String  CCTV_IP;            //	N	VARCHAR2(20)	Y			목포 CCTV 제어 IP
    int     CCTV_PORT;          //	N	NUMBER(5)	    Y	1852		목포 CCTV 제어 PORT
    String  CCTV_ID;            //	N	VARCHAR2(20)	Y	'root'		목포 CCTV 제어 ID
    String  CCTV_PSWD;          //	N	VARCHAR2(20)	Y	'1234'		목포 CCTV 제어 PSWD
    int     CCTV_CHNL;          //	N	NUMBER(5)	    Y	1		목포 CCTV 제어 CHANNEL

    INT_CCTV_STATE  STATE;

public:
    TItsMap<int, TCctvPset*> FLists;

public:
    __property String  CCTV_CTLR_NMBR     = { read = CTLR_NMBR,     write = CTLR_NMBR     };
    __property String  CCTV_CTLR_ID       = { read = CTLR_ID,       write = CTLR_ID       };
    __property String  CCTV_NM            = { read = NAME,          write = NAME          };
    __property String  CCTV_CTLR_IP       = { read = CTLR_IP,       write = CTLR_IP       };
    __property int     CCTV_CTLR_PORT     = { read = CTLR_PORT,     write = CTLR_PORT     };
    __property int     CCTV_CTLR_LOCAL_NO = { read = CTLR_LOCAL_NO, write = CTLR_LOCAL_NO };
    __property String  CCTV_TYPE_CD       = { read = TYPE_CD,       write = TYPE_CD       };

};
//---------------------------------------------------------------------------
typedef std::map<String, TCctvCtlr*>::iterator   CctvIterator;
//---------------------------------------------------------------------------

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

private:
	TStream *FImgStream;

public:
    TItsMap<String, TCctvCtlr*> FLists;

public:
    bool LoadFromDb(TADOConnection *ADbConn=NULL);
    bool LoadStatusFromDb(TADOConnection *ADbConn=NULL);
    bool DeleteCctv(TCctvCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool InsertCctv(TCctvCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool UpdateCctv(TCctvCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeCctv(TCctvCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeFcltInfo(TCctvCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool GetNextCctvId(int &ANmbr, int &AId, TADOConnection *ADbConn=NULL);

    bool LoadPreSet(TADOConnection *ADbConn=NULL);
    bool SavePreSet(TCctvCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool DeletePreSet(TCctvCtlr *AObj, int APsetNmbr, TADOConnection *ADbConn=NULL);
    bool MergePreSet(TCctvCtlr *AObj, TCctvPset* APset, TADOConnection *ADbConn=NULL);

    bool InsCctvControlHs(String ACtlDt, String ACctvNmbr, String ACtlType, String ACtlVal, String ACtlRes, String AUserId, TADOConnection *ADbConn=NULL);
};
//---------------------------------------------------------------------------
extern TCctvCtlrManager *CctvCtlrManager;
//---------------------------------------------------------------------------

#endif
