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

import { GearResp, GearReq } from "../models/gear";

import { BaseService } from "./base.service";
import { RefData } from "../models/ref-data.enum";

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

  public getListOfGears(): Observable<Array<GearResp>> {
    let callToApi = this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, { headers: this.headers });
    return this.serviceRefData.get<Array<GearResp>>(RefData.Gear, callToApi);
  }

  public AddGear(name: string,
                 manufacturer: string,
                 minSize: number,
                 maxSize: number,
                 aad: string,
                 mainCanopy: string,
                 reserveCanopy: string)
  {
    const bodyNewGear: GearReq = {
      id: 0,
      name: name,
      manufacturer: manufacturer,
      minSize: minSize,
      maxSize: maxSize,
      aad: aad,
      mainCanopy: mainCanopy,
      reserveCanopy: reserveCanopy
    };

    return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers});
  }
}
