import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Boilerplate } from '../models/boilerplate.model';
import { GroupBoilerplate } from '../models/boilerplate.model';
import { InferenceResults } from '../models/boilerplate.model';
import { environment } from '../../environments/environment';
const baseUrl = '/boilerplates/';
const inferUrl = '/infer/';
const baseUrlgb = environment.apiroot+'api-auth/groupboilerplates/';
const genericbaseUrl = environment.apiroot+'api-auth';

@Injectable({
  providedIn: 'root'
})
export class BoilerplateService {
  
  constructor(private http: HttpClient) { }

  creategroupboil(data: any): Observable<any> {
    return this.http.post(baseUrlgb, data);
  }

  getAllgroupboil(): Observable<any> {
    return this.http.get<[GroupBoilerplate]>(baseUrlgb);
  }

  deletegroupboil(id: any): Observable<any> {
    return this.http.delete(`${baseUrlgb}${id}`);
  }

  getAllInfer(gb: any): Observable<InferenceResults[]> {
    return this.http.get<[InferenceResults]>(baseUrlgb + gb + inferUrl);
  }

  inferUpdate(gb: any,id: any, data: any): Observable<any> {
    return this.http.put(`${baseUrlgb}${gb}${inferUrl}${id}/`, data);
  }

  getAll(gb: any): Observable<Boilerplate[]> {
    //console.log(baseUrlgb + gb + baseUrl)
    return this.http.get<Boilerplate[]>(baseUrlgb + gb + baseUrl);
  }

  getAllData(gb: any): Observable<Boilerplate[]> {
    return this.http.get<Boilerplate[]>(baseUrlgb + gb + baseUrl+ `boilerplatedata/`);
  }

  get(gb: any, id: any): Observable<Boilerplate> {
    return this.http.get(`${baseUrlgb}${gb}${baseUrl}${id}`);
  }

  create(gb: any, data: any): Observable<any> {
    return this.http.post(baseUrlgb + gb + baseUrl, data);
  }

  update(gb: any,id: any, data: any): Observable<any> {
    return this.http.put(`${baseUrlgb}${gb}${baseUrl}${id}/`, data);
  }

  delete(gb: any, id: any): Observable<any> {
    return this.http.delete(`${baseUrlgb}${gb}${baseUrl}${id}`);
  }

  findByTitle(gb: any, title: any): Observable<Boilerplate[]> {
    return this.http.get<Boilerplate[]>(`${baseUrlgb}${gb}${baseUrl}title=${title}`);
  }

  searchinstances(gb: any, instance: any): Observable<any> {
    return this.http.get(`${baseUrlgb}${gb}`+`/search`+`/${instance}`);
  }

  getOntolgies(): Observable<any> {
    return this.http.get(`${genericbaseUrl}`+`/ontologies`+`/`);
  }

  getCurrentOntolgies(gb: any): Observable<any> {
    return this.http.get(`${genericbaseUrl}`+`/getontology/${gb}`, { responseType: "blob" });
  }

}
