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";
import {UsersoffersDataService} from "./usersoffers-data.service";

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

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

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

      if( this.sessionDataProviderService.session == ''){
        clearInterval(interval);
        return;
      }
      this.bannersDataService.getBannersData();
      this.marketDataService.getJobsData();
      this.tasksDataService.getJobsData();
      this.usersoffersDataService.getMyOffersData();

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

}
