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

const SERVER_URL = '/api/server';

@Injectable()
export class ServerService {
  constructor(
    private http: HttpClient
  ) {}

  getStatus(): Observable<number> {
    return this.http.get<number>(`${SERVER_URL}/status`);
  }

  startServer(): Observable<any> {
    return this.http.post(`${SERVER_URL}/start`, undefined);
  }

  stopServer(): Observable<any> {
    return this.http.post(`${SERVER_URL}/stop`, undefined);
  }

  restartServer(): Observable<any> {
    return this.http.post(`${SERVER_URL}/restart`, undefined);
  }
}
