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

import { JumpTypeResp, JumpTypeReq } from "../models/jumpType";

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

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

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

  public AddJumpType(jumptypetName: string) {
    const bodyJumpType: JumpTypeReq = {
      id: 0,
      name: jumptypetName
    };

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