#include "AppDelegate.h"

#include "../cocos2d/cocos/platform/CCGLView.h"
#include "com/pokkt/app/scene/PokktScene.h"

USING_NS_CC;

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate() 
{
}

void AppDelegate::initGLContextAttrs()
{
    //set OpenGL context attributions,now can only set six attributions:
    //red,green,blue,alpha,depth,stencil
    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

    GLView::setGLContextAttrs(glContextAttrs);
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview)
    {
        glview = GLViewImpl::create("Pokkt App");
        director->setOpenGLView(glview);
    }
    glview->setDesignResolutionSize(750, 1334, ResolutionPolicy::FIXED_HEIGHT);
    //glview->setContentScaleFactor(0.5f);

    // create a scene. it's an autorelease object
    _scene = PokktScene::createScene();

    // run
    director->runWithScene(_scene);
    
    
    // set pokkt config
    std::string appId = "a2717a45b835b5e9f50284a38d62a74e";
    std::string securityKey = "iJ02lJss0M";
    
    appId = "cc41e865391d6ea371b18aff27cc10e6";
    securityKey = "4a069e89fe4a4e4f58a26f8bff2974ba";
    
    PCPokktAds::shouldDebug(true);
    PCPokktAds::setPokktConfig(appId, securityKey);
    
    PCPokktAds::setCallbackExtraParam("{\"Key 1\":\"value 1\",\"Key 2\":\"value 2\",\"Key 3\":\"value 3\",\"Key 4\":\"value 4\"}");

    return true;
}

void AppDelegate::applicationDidEnterBackground()
{
    Director::getInstance()->stopAnimation();

    // SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}

void AppDelegate::applicationWillEnterForeground()
{
    Director::getInstance()->startAnimation();

    // SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
    
    auto layer = _scene->getChildByName<PokktScene*>("sceneLayer");
    layer->handleEnterForeground();
}
