//
//  Config.cpp
//  Game
//
//  Created by Darvydas on 26/01/2019.
//

#include "Game/GameScene/World/Config.hpp"
#include "Utils/json/Manager.hpp"

namespace Game
{
    namespace World
    {
        CConfig* CConfig::instance = nullptr;

        CConfig* CConfig::getInstance()
        {
            if (instance == 0)
            {
                instance = new CConfig();
            }
            return instance;
        }
        
        CConfig::CConfig()
        {
            
        }
        
        CConfig::~CConfig()
        {
        }
        
        std::vector<std::string> CConfig::getInteractiveObjects(int level)
        {
            // parse config
            json::CManager* manager = json::CManager::getInstance();
            
            manager->openFile("Levels.json");
            
            rapidjson::Document& document = *manager->getOpenedDocument();
            
            std::string strName = cocos2d::StringUtils::format("Level_%d", level);
            
            std::vector<std::string> vInteractiveObjectsToReturn;
            
            if(document.HasMember(strName.c_str()))
            {
                const rapidjson::Value& array = document[strName.c_str()];  // you are missing this
                assert(array.IsArray());
                for (rapidjson::SizeType i = 0; i < array.Size(); i++)
                {
                    const rapidjson::Value& value = array[i];
                    
                    vInteractiveObjectsToReturn.push_back(value.GetString());
                }
            }
            
            return vInteractiveObjectsToReturn;
        }
        
    }
}
