require("./AnyThinkAds/ATJSSDK");

var ATSDKMgrJS = cc.Class({

    name: "ATSDKMgrJS",

    /** 代理脚本(TS) */
    proxy: null,

    ctor: function () {
        console.log("ATSDKMgrJS.js created! ")
    },

    /** 初始化Sdk */
    initATJSSDK: function (appid, appsecret) {
        
        ATJSSDK.setLogDebug(true);

        var customMap = {
            "appCustomKey1": "appCustomValue1",
            "appCustomKey2": "appCustomValue2"
        };

        ATJSSDK.initCustomMap(customMap);
        // ATJSSDK.setPlacementCustomMap(customPlacementId, placementCustomMap);

        //替换------------------------------------------------------------------
        var placementCustomMap = {
            "placementCustomKey1": "placementCustomValue1",
            "placementCustomKey2": "placementCustomValue2"
        };

        ATJSSDK.setPlacementCustomMap(this.placementID(), placementCustomMap);
        //ATJSSDK.setGDPRLevel(ATJSSDK.NONPERSONALIZED);

        var GDPRLevel = ATJSSDK.getGDPRLevel();
        // ATJSSDK.printLog("Current GDPR Level :" + GDPRLevel);

        if (cc.sys.os === cc.sys.OS_IOS) {
            ATJSSDK.initSDK(appid, appsecret);
        } else if (cc.sys.os === cc.sys.OS_ANDROID) {
            ATJSSDK.initSDK(appid, appsecret);
        }

        ATJSSDK.getUserLocation(function (userLocation) {
            // ATJSSDK.printLog("getUserLocation callback userLocation :" + userLocation);
            if (userLocation === ATJSSDK.kATUserLocationInEU) {
                if (ATJSSDK.getGDPRLevel() === ATJSSDK.UNKNOWN) {
                    ATJSSDK.showGDPRAuth();
                }
            }
        });
    },

    placementID() {
        console.log("this.proxy", this);
        console.log("this.proxy", this.proxy);
        return this.proxy.placementID();
    }
});

module.exports = ATSDKMgrJS;
if (!cc["ATSDKMgrJS"]) {
    cc["ATSDKMgrJS"] = new ATSDKMgrJS();
}
