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

#ifndef CDSCrossFH
#define CDSCrossFH
//---------------------------------------------------------------------------
#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 TCrossCam : public TCDSObject
{
public:
    TCrossCam()
    {
        ANGLE     = 0;
    };
    ~TCrossCam() {};

private:

public:
    String  CROSS_ID;

    String  IP;
    String  ID;
    String  PWD;
    String  RTSP_URL;
    int     RTSP_PORT;
    int     HTTP_PORT;

    String  DIRECTION;
    int     ANGLE;

    String  RIGHT_USE;

public:
    void Copy(TCrossCam *AObj);

public:
    __property String  CAM_ID   = { read = CTLR_NMBR,     write = CTLR_NMBR     };
    __property String  CAM_NM   = { read = NAME,          write = NAME          };

};

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

public:
    int     ZOOM_LEVEL;
    String  LOCAL_GROUP_ID;
    String  CROSS_TYPE;

public:
    TItsMap<String, TCrossCam*> FLists;

public:
    __property String  CROSS_ID   = { read = CTLR_NMBR,     write = CTLR_NMBR     };
    __property String  CROSS_NM   = { read = NAME,          write = NAME          };

};
//---------------------------------------------------------------------------
typedef std::map<String, TCross*>::iterator   CrossIterator;
//---------------------------------------------------------------------------

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

private:

public:
    TItsMap<String, TCross*> FLists;
    TItsMap<String, TCrossCam*> FCamLists;

public:
    bool LoadFromDb(TADOConnection *ADbConn=NULL);
    bool LoadCrossCam(TADOConnection *ADbConn=NULL);

    bool LoadStatusFromDb(TADOConnection *ADbConn=NULL);
    bool DeleteCross(TCross *AObj, TADOConnection *ADbConn=NULL);
    bool InsertCross(TCross *AObj, TADOConnection *ADbConn=NULL);
    bool UpdateCross(TCross *AObj, TADOConnection *ADbConn=NULL);
    bool MergeCross(TCross *AObj, TADOConnection *ADbConn=NULL);

    bool MergeFcltInfo(TCross *AObj, TADOConnection *ADbConn=NULL);
    bool GetNextCrossId(int &ANmbr, int &AId, TADOConnection *ADbConn=NULL);

    bool SaveCrossCam(TCrossCam *AObj, TADOConnection *ADbConn=NULL);
    bool DeleteCrossCam(TCrossCam *AObj, TADOConnection *ADbConn=NULL);
    bool MergeCrossCam(TCrossCam *AObj, TADOConnection *ADbConn=NULL);

    bool MergeFcltInfo2(TCrossCam *AObj, TADOConnection *ADbConn=NULL);
};

//---------------------------------------------------------------------------
extern TCrossManager *CrossManager;
//---------------------------------------------------------------------------

#endif
