import { Injectable } from '@angular/core';
import {SessionDataProviderService} from "./session-data-provider.service";
import {MarketDataService} from "./market-data.service";
import {TasksDataService} from "./tasks-data.service";
import {BannersDataService} from "./banners-data.service";

@Injectable({
  providedIn: 'root'
})
export class IntervalRefreshService {

  constructor( public sessionDataProviderService:SessionDataProviderService,
               public marketDataService:MarketDataService,
               public tasksDataService:TasksDataService,
               public bannersDataService:BannersDataService) {
    this.marketDataService.getJobsData();
  }

  startIntervalCalls(){
    console.log("Hello Start ",this.sessionDataProviderService.session,this.sessionDataProviderService.refresh  );
    var interval = setInterval( ()=> {

      if( this.sessionDataProviderService.session == ''){
        clearInterval(interval);
        return;
      }
      console.log("Interval Function ",this.sessionDataProviderService.session  );
      this.marketDataService.getJobsData();
      this.tasksDataService.getJobsData();
      this.bannersDataService.getBannersData();

    }, this.sessionDataProviderService.refresh*2);
  }

}
