const cm = require("../common.js");
const c = require("./credentials.js");
const PDE = require("../pdemanager.js");

cm.config({
    app_id: c.APP_ID,
    app_code: c.APP_CODE,
});


let TheBB = {
    lngm: 2.2721050262451286,
    lngM: 2.327894973754894,
    latm: 48.841644499517614,
    latM: 48.878348771567445
};


let TheLayers = {
    POI_BIG: {
        callback: pdeGotPOIBig,
        level: 9
    },

     
    LINK_ATTRIBUTE_FC: {
        callback: pdeGotLinkAttrib,
        fcLayers: [1, 3]
    }

};


let pde = new PDE.PDEManager({rps: 10});



test('PDE bounding box', async () => {
    expect.assertions(1);
    pde.setLayers(TheLayers);
    pde.setBoundingBox(TheBB);
    
    let res = await pde.run();    
    expect(res).toEqual(8);

});


test('PDE Coords', async () => {
    expect.assertions(2);
    TheLayers = {
   
        LINK_ATTRIBUTE_FC: {
            callback: pdeGotLinkAttrib,
            fcLayers: [2]
        }
    
    };
    pde.setLayers(TheLayers);
    pde.setCoords([[51.561, -0.4958]]);
    let res =pde.getTilesInfo();
    console.log(res);
    expect(res.length).toEqual(1); // 1 tile

    res = await pde.run();    
    expect(res).toEqual(1); // 1 tile

});



function pdeGotPOIBigger(res) {
    //console.log("pdeGotPOIBigger", res.Meta);
}

function pdeGotPOIBig(res) {
    //console.log("pdeGotPOIBig", res.Meta);
}

function pdeGotPOISmall(res) {
    //console.log("pdeGotPOISmall", res);
}

function pdeGotPOISmaller(res) {
    //console.log("pdeGotPOISmaller", res);
}


function pdeGotLinkAttrib(res) {
   console.log("pdeGotLinkAttrib", res.Meta);
}