//---------------------------------------------------------------------------
#pragma hdrstop

#include "CDSVmsSizeTypeF.h"
#include "AppGlobalF.h"

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

#pragma package(smart_init)

//---------------------------------------------------------------------------
TVmsSizeType::TVmsSizeType(String ATYPE_CD, String ATYPE_NM, String ATYPE_DESC, int AWDTH, int AHGHT, int AROWS, int ACOLS, String AUSE_YN)
{
    TYPE_CD   = ATYPE_CD;
    TYPE_NM   = ATYPE_NM;
    TYPE_DESC = ATYPE_DESC;
    WDTH      = AWDTH;
    HGHT      = AHGHT;
    ROWS      = AROWS;
    COLS      = ACOLS;
    USE_YN    = AUSE_YN;
}

//---------------------------------------------------------------------------
TVmsSizeTypeManager *VmsSizeTypeManager = NULL;
//---------------------------------------------------------------------------

TVmsSizeTypeManager::TVmsSizeTypeManager()
{
}
//---------------------------------------------------------------------------
TVmsSizeTypeManager::~TVmsSizeTypeManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------
int TVmsSizeTypeManager::Load()
{
    FLists.RemoveAll();

    String apiUri = g_AppCfg.sRestApiUri + "/api/vms/common/vms-type";
    TMcJsonItem *ObjList = NULL;
    try {
        ObjList = TRestObjectManager::RequestGet(apiUri);
        if (ObjList == NULL) {
            return 0;
        }

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sTypeCd = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_type_cd");
            String sTypeNm = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_type_nm");
            String sTypeDesc = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_type_desc");
            String sWidth  = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_wdth");
            String sHeight = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_hght");
            String sRows  = TRestObjectManager::GetValue(ObjList->Items[ii], "row_num");
            String sCols = TRestObjectManager::GetValue(ObjList->Items[ii], "col_num");
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            int nW = sWidth.ToIntDef(320);
            int nH = sHeight.ToIntDef(64);
            int nRows = sRows.ToIntDef(2);
            int nCols = sCols.ToIntDef(10);

            TVmsSizeType *Obj = new TVmsSizeType(sTypeCd, sTypeNm, sTypeDesc, nW, nH, nRows, nCols, sUseYn);
            FLists.Push(sTypeCd, Obj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return 0;
}
//---------------------------------------------------------------------------
TVmsSizeType* TVmsSizeTypeManager::Find(String ATypeCd)
{
    return FLists.Find(ATypeCd);
}
//---------------------------------------------------------------------------
