import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { IUser } from '../models/user';
import { HttpClient } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";

@Injectable({
  providedIn: 'root',
})
export class UserService {
  constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
  }

  ApiEndpoint() {
    return this.appConfig.getConfig("apiEndPoint");
  }

  getCurrentUser(): Observable<IUser> {
    return this.httpClient.get<IUser>(`${this.ApiEndpoint()}/api/v1/users/currentuser`);
  }

  updateCurrentUser(user: IUser): Observable<IUser> {
    return this.httpClient.put<IUser>(`${this.ApiEndpoint()}/api/v1/users/${user.code}`, user);
  }
}
