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

#include "CDSFontNameF.h"
#include "AppGlobalF.h"

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

#pragma package(smart_init)

//---------------------------------------------------------------------------
TVmsFontName::TVmsFontName(int AFONT_CD, String AFONT_NM, String AFONT_DESC)
{
    FONT_CD   = AFONT_CD;
    FONT_NM   = AFONT_NM;
    FONT_DESC = AFONT_DESC;
    USE_YN    = "Y";
}

//---------------------------------------------------------------------------
TFontNameManager *FontNameManager = NULL;
//---------------------------------------------------------------------------

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

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

        for (int ii = 0; ii < ObjList->Count; ii++) {
            String sUseYn = TRestObjectManager::GetValue(ObjList->Items[ii], "use_yn");
            if (sUseYn != "Y") {
                continue;
            }

            String sCD = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_name_cd");
            String sNM = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_name");
            String sDESC = TRestObjectManager::GetValue(ObjList->Items[ii], "vms_font_name_desc");

            TVmsFontName *pObj = new TVmsFontName(sCD.ToIntDef(0), sNM, sDESC);
            FLists.Push(pObj->FONT_CD, pObj);
        }
    } __finally {
        if (ObjList) delete ObjList;
    }
    return 0;
}
//---------------------------------------------------------------------------
TVmsFontName* TFontNameManager::Find(int ATypeCd)
{
    return FLists.Find(ATypeCd);
}
//---------------------------------------------------------------------------
