import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { Server } from './server';

@Injectable({
  providedIn: 'root'
})
export class ServerService {
  baseUrl: string = environment.serviceUrl;

  constructor(private httpClient: HttpClient) {
  }

  Get(): Observable<any> {
    return this.httpClient.get<any>(this.baseUrl + 'api/ServerApi')
  }
  GetActive(): Observable<any> {
    return this.httpClient.get<any>(this.baseUrl + 'api/ServerApi/GetActiveServer')
  }
  Post(server: Server): Observable<any> {

    let header = new HttpHeaders();
    header = header.set('Content-Type', 'application/json; charset=utf-8');
    return this.httpClient.post(this.baseUrl + 'api/ServerApi/add', server, { headers: header, observe: 'response' })
  }
  Delete(server: Server) {
    let header = new HttpHeaders();
    header = header.set('Content-Type', 'application/json; charset=utf-8');
    return this.httpClient.post(this.baseUrl + 'api/ServerApi/activeordeactive', server, { headers: header, observe: 'response' })
  }
  Put(server: Server): Observable<any> {
    let header = new HttpHeaders();
    header = header.set('Content-Type', 'application/json; charset=utf-8');
    return this.httpClient.post(this.baseUrl + 'api/ServerApi/Update', server, { headers: header, observe: 'response' })
  }
  GetServerType(): Observable<any> {
    return this.httpClient.get<any>(this.baseUrl + 'api/ServerApi/GetServerType');
  }
}
