import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { FleioApiService } from '../../fleio-api.service';
import { ConfigService } from '@shared/config/config.service';
import { Observable } from 'rxjs';
import { ITicketSignatureModel } from '@fleio-api/plugins/tickets/model/ticket-signature.model';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';


export interface getUserSettingsParams {
  new_user: boolean;
  user_id?: FleioId;
}


@Injectable({
  providedIn: 'root'
})
export class TicketStaffNotificationsSettingsApiService extends FleioApiService<ITicketSignatureModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('plugins/tickets/notifications_settings'));
  }

  getCurrentUserSettings(): Observable<FleioObjectsList<any>> {
    return this.getAction( 'get_current_user_settings');
  }

  saveCurrentUserSettings(value): Observable<FleioObjectsList<any>> {
    return this.postAction( 'save_current_user_settings', value);
  }

  getUserSettings(userID: FleioId): Observable<FleioObjectsList<any>> {
    const queryParams = {
      new_user: !userID,
    } as getUserSettingsParams;
    if (userID) {
      queryParams.user_id = userID;
    }
    return this.getAction( 'get_user_settings', queryParams);
  }

  saveUserSettings(value, userID: FleioId): Observable<FleioObjectsList<any>> {
    value.user_id = userID;
    return this.postAction( 'save_user_settings', value);
  }

}
