/*
 * Copyright (c) Created by Can Kuşcu on 26/4/2018
 */

const moment = require('moment');
const PlayerDB = require('../PlayerDB');
let db = new PlayerDB();
global.db = db;
global.deviceID = 7780;
global.url = 'http://cdn.smg.com.tr/';




async function main() {
    await db.initsync()


    const schedules = require('../../downloader/schedulesDownloader');
    let sch = new schedules({db, moment});
    const announces = require('../../downloader/announcesDownloader');
    let ann = new announces({db, moment});
    ann.start();
// const schedules = require('./schedulesDB');
// let sch = new schedules({db, moment});
// const announces = require('./announcesDB');
// let ann = new announces({db, moment});



    let q1 = await ann.checkDownloads();
    let q = await sch.checkDownloads1();
    // console.log('total announces to download ' + q1.length + ' ' +new moment().utc(true).toJSON().substr(11,19));
    // console.log('total schedule files to download ' + q.length + ' '+ new moment().utc(true).toJSON().substr(11,19));
    // console.log('bitti ' + new moment().utc(true).toJSON().substr(11,19));

    await q1.forEach(obj => {
        dm.addFileToQue(obj.FileName);
        });
        await q.forEach(obj => {
            //console.log(obj.FileName);
            dm.addFileToQue(obj.FileName);
        });
}


main();

setTimeout(() => {

    dm.start();
}, 10000);
// dm.start();