// const bass = require('./smg/player/basswrapper').basswrapper;
// const basslib = new bass();

const moment = require('moment');
const PlayerDB = require('../db/PlayerDB');
let db = new PlayerDB();

const Schedulesdb = require('../db/schedulesDB');
const Announcesdb = require('../db/announcesDB');
const SMGPush = require('../push/SMGPush');
const Utils = require('../utils/smgutils');
var schedulePlayer = require('../playerSerkan/schedulePlayer1')
let masterMixer=require('../playerSerkan/masterMixer')
let utils = new Utils();



const SchedulesDownloader = require('../downloader/schedulesDownloader');
const AnnouncesDownloader = require('../downloader/announcesDownloader');

async function Main() {
  //await config
  let config = utils.readConfig();
  config.Settings.deviceID = 7787;
  global.deviceID = config.Settings.deviceID;
  global.url = config.Settings.downloadURL;

  let connectionUrl = config.Settings.serviceUrl, retryConnect = true, announcesdb, schedulesdb;

  //await db init
  await db.initsync();
  global.db = db;
  schedulesdb = new Schedulesdb({ db, moment });
  announcesdb = new Announcesdb({ db, moment });


  let push = new SMGPush({ connectionUrl, retryConnect, db, schedulesdb, announcesdb });
  await push.setUser({
    IP: '192.168.2.22',
    deviceID: config.Settings.deviceID,
    deviceName: 'can',
    userType: 7,
    version: '8.7.0',
    config
  });
  //push.setProxy(proxyOptions)
  push.connect();


  var sp = new schedulePlayer({db,moment,utils,config,schedulesdb,announcesdb,decodeOnly:true})


  var MasterMixer=new masterMixer({db,moment,utils,config})


  var result= MasterMixer.addChannelToMixer(sp.mixer)
  await sp.checkNextPlay();



  MasterMixer.setVolume(sp.mixer,100);


  let announcesDownloader = new AnnouncesDownloader({ db, moment, config, utils });
  await announcesDownloader.start();

  let schedulesDownloader = new SchedulesDownloader({ db, moment, config, utils });
  await schedulesDownloader.start();


}

Main();
// setInterval(() => {}, 500)

