import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { INotificationModel } from './model/notification.model';
import { FleioApiService } from '../fleio-api.service';
import { ConfigService } from '../../config/config.service';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { Observable } from 'rxjs';
import {
  IUserNotificationSettingsResponseModel
} from '@fleio-api/notifications/model/user-notification-settings-response.model';


@Injectable({
  providedIn: 'root'
})
export class UserNotificationsApiService extends FleioApiService<INotificationModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('notifications'));
  }

  setViewed(notificationId: FleioId): Observable<any> {
    return this.objectPostAction(notificationId, 'view', {});
  }

  setUnseen(notificationId: FleioId): Observable<any> {
    return this.objectPostAction(notificationId, 'unseen', {});
  }

  getPanelNotifications() {
    return this.getAction('get_panel_notifications');
  }

  getNotificationsSettings(): Observable<IUserNotificationSettingsResponseModel> {
    return this.getAction('get_notifications_settings');
  }
}
