import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';
import { User } from './user';
import { Observable } from 'rxjs';
import { HttpHeaders, HttpClient } from '@angular/common/http';
let header = new HttpHeaders();
header = header.set('Content-Type', 'application/json; charset=utf-8');
@Injectable({
  providedIn: 'root'
})
export class UserService {

  baseUrl: string = environment.serviceUrl;
  constructor(private httpClient: HttpClient) { }

  GetByRoleId(user: User): Observable<any> {
    return this.httpClient.post<any>(this.baseUrl + 'api/UserApi/GetByRoleId', user, { headers: header, observe: 'response' });
  }
  Get(): Observable<any[]> {
    return this.httpClient.get<any[]>(this.baseUrl + 'api/UserApi');
  }
  GetActive(): Observable<any[]> {
    return this.httpClient.get<any[]>(this.baseUrl + 'api/UserApi/GetActiveUsers');
  }

  Delete(user: User) {
    header = new HttpHeaders();
    header = header.set('Content-Type', 'application/json; charset=utf-8');
   // return this.httpClient.post(this.baseUrl + 'api/UserApi/delete', user, { headers: header, observe: 'response' });
    return this.httpClient.post(this.baseUrl + 'api/UserApi/delete', user, { observe: 'response' })
  
  }
  GetUsersByDepartment(departmentid: number): Observable<any[]> {
    return this.httpClient.get<any[]>(this.baseUrl + 'api/UserApi/GetUsersByDepartment/'+ departmentid)
  }
}
