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

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

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

  loadUserNotifications(): Observable<any> {
    return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/notifications`);
  }

  readUserNotification(notificationCode: string): Observable<any> {
    return this.httpClient.put<any>(`${this.ApiEndpoint()}/api/v1/notifications/${notificationCode}`, null);
  }

  deleteUserNotification(notificationCode: string): Observable<any> {
    return this.httpClient.delete<any>(`${this.ApiEndpoint()}/api/v1/notifications/${notificationCode}`);
  }

  getUserConnections(userCode: string, active: boolean): Observable<IUser[]> {
    return this.httpClient.get<any>(`${this.ApiEndpoint()}/api/v1/users/${userCode}/connections?active=${active}`);
  }
}
