import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { Customer } from './customer';

@Injectable({
    providedIn: 'root'
})
export class CustomerService {
    baseUrl: string = environment.serviceUrl;

    constructor(private httpClient: HttpClient) {
    }

    Get(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/CustomerApi');
    }
    GetActive(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/CustomerApi/GetActiveCustomer');
    }
    Post(customer: Customer): Observable<any> {

        let header = new HttpHeaders();
        header = header.set('Content-Type', 'application/json; charset=utf-8');
        return this.httpClient.post(this.baseUrl + 'api/CustomerApi/add', customer, { headers: header, observe: 'response' });
    }
    Delete(customer: Customer) {
        let header = new HttpHeaders();
        header = header.set('Content-Type', 'application/json; charset=utf-8');
        return this.httpClient.post(this.baseUrl + 'api/CustomerApi/activeordeactive',
            customer, { headers: header, observe: 'response' });
    }
    Put(customer: Customer): Observable<any> {
        let header = new HttpHeaders();
        header = header.set('Content-Type', 'application/json; charset=utf-8');
        return this.httpClient.post(this.baseUrl + 'api/CustomerApi/Update', customer, { headers: header, observe: 'response' });
    }

}
