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

import { AircraftResp, AircraftReq } from '../models/aircraft';

import { BaseService } from './base.service';


@Injectable()
export class AircraftService extends BaseService {
  constructor(private http: HttpClient) {
    super();
  }

  public getListOfAircrafts(): Observable<Array<AircraftResp>> {
    return this.http.get<Array<AircraftResp>>(
      `${this.apiUrl}/Aircraft`,
      { headers: this.headers }
    );
  }

  public AddAircraft(aircraftName: string) {
    const bodyNewAircraft: AircraftReq = {
      id: 0,
      name: aircraftName
    };

    this.http
      .post(`${this.apiUrl}/Aircraft`, bodyNewAircraft, {
        headers: this.headers
      })
      .subscribe(data => console.log(data));
  }

}
