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

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

    constructor(private httpClient: HttpClient) {
    }

    Get(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/UnitApi')
    }
    GetActive(): Observable<any> {
        return this.httpClient.get<any>(this.baseUrl + 'api/UnitApi/GetActiveUnit')
    }
    Post(unit: Unit): Observable<any> {

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