import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Prefix } from '../models/prefix.model';
import { environment } from '../../environments/environment';

const baseUrl = environment.apiroot + 'api-auth/groupboilerplates/0/boilerplates/';
const baseUrl2 = environment.apiroot + 'api-auth/groupboilerplates/';
const Url = '/prefix/';

@Injectable({
  providedIn: 'root'
})
export class PrefixService {

  constructor(private http: HttpClient) { }

  getAll(boilerplate: any): Observable<Prefix[]> {
    return this.http.get<Prefix[]>(`${baseUrl}${boilerplate}${Url}`);
  }

  get(boilerplate: any, id: any): Observable<Prefix> {
    return this.http.get(`${baseUrl}${boilerplate}${Url}${id}`);
  }

  create(boilerplate: any, data: any): Observable<any> {
    return this.http.post(`${baseUrl}${boilerplate}${Url}`, data);
  }

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

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

  getsimpleprefix(gb: any): Observable<any> {
    return this.http.get(`${baseUrl2}${gb}${Url}`+`choices/simpleprefix/`);
  }
}
