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

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

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

  constructor(private http: HttpClient) { }

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

  get(boilerplate: any, id: any): Observable<Suffix> {
    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}`);
  }

  getsuffix(): Observable<any> {
    return this.http.get(environment.apiroot +`api-auth/suffix/choices/suffix/`);
  }

  getnumunits(): Observable<any> {
    return this.http.get(environment.apiroot +`api-auth/suffix/choices/numunits/`);
  }

  getflow(): Observable<any> {
    return this.http.get(environment.apiroot +`api-auth/suffix/choices/flow/`);
  }
  
  getsuffixflow(gb: any): Observable<any> {
    return this.http.get(`${baseUrl2}${gb}`+`/prefix/choices/simpleprefix/`);
  }

}
