import { Injectable } from '@angular/core';
import { CurrentDeviceService } from '@iotize/ionic';
import { <%= classify(appName) %> } from 'tap-api';
import { Tap } from '@iotize/device-client.js';

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

  public data: <%= classify(appName) %>.DataManager;

  constructor(tapService: CurrentDeviceService) {
    this.data = <%= classify(appName) %>.DataManager.create(tapService.tap);

    tapService
      .tapChanged
      .subscribe((newTap: Tap) => {
        console.info('Tap changed!');
        if (this.data) {
          this.data.stopAll();
        }
        this.data = <%= classify(appName) %>.DataManager.create(newTap);
      });
  }
  
  public stop() {
    if (this.data) {
      this.data.stopAll();
    }
  }
  
}
