import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Inject, Injectable } from '@angular/core';
import { DirUser } from '../../models/user-management.api.models';
import { UrlService } from './url.service';

@Injectable({
  providedIn: 'root'
})
export class DirService {
  private baseUrl: string
  constructor(private http: HttpClient, urlService : UrlService) {
    this.http = http;
    this.baseUrl = urlService.apiRoute.directory;
  }

  getUser(groupName: string): Observable<DirUser[]> {
    let params = new HttpParams();
    if (groupName) {
      params = params.set('groupName', groupName);
    }

    return this.http.get<DirUser[]>(this.baseUrl, { params, withCredentials: true });
  }
}