import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
// import { BehaviorSubject } from 'rxjs';
import { FactionPoints } from './FactionPoints';
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'
  })
};

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

  url : string;

  constructor(private http: HttpClient) {
    this.url = "https://api.myjson.com/bins/l1mki";
   }

  getPoints$(): Observable<FactionPoints>  {
    return this.http.get<FactionPoints>(this.url);
  }

  updatePoints$(points: FactionPoints): Observable<FactionPoints>  {
    return this.http.put<FactionPoints>(this.url, points, httpOptions);
  }
}
