import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';

/*
  Generated class for the VespotServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class VespotServiceProvider {

	URL: string;

  constructor(public http: HttpClient) {
	this.URL = 'http://api.vespot.com';
  }

  getDevices(auth) {
    return this.http.get(this.URL + '/devices', {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
  }

  getDeviceById(auth, deviceId) {
    return this.http.get(this.URL + '/devices?id=' + deviceId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
  }

  getPositionById(auth, positionId) {
    return this.http.get(this.URL + '/positions?positionId=' + positionId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
  }

  getPositionByDeviceId(auth, deviceId) {
    return this.http.get(this.URL + '/positions/lastdeviceposition?deviceId=' + deviceId, {headers: new HttpHeaders().set('Authorization', 'Basic ' + btoa(auth))});
  }
}
