import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Product } from '../models/product.model';
import { environment } from '../../../../environments/environment';
import { delay } from 'rxjs/operators';

@Injectable()
export class ProductsService {
    constructor(protected http: HttpClient) {
    }

    loadProducts(): Observable<any> {
        return this.http.get(environment.apiBaseUrl + '/products').pipe(delay(100));
    }

    deleteProduct(id: number) {
        return this.http.delete(environment.apiBaseUrl + '/product/delete/' + id );
    }

    addProduct(item: Product): Observable<Product> {
        return this.http.post(environment.apiBaseUrl + '/product', item);
    }

    updateProduct(item: Product): Observable<Product> {
        return this.http.post(environment.apiBaseUrl + '/product', item);
    }

}
