import { Injectable } from '@angular/core';
import { DiscoverHost, Zone } from '@overflow/model/discovery';
import { Observable, BehaviorSubject } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class DiscoveryConfigService {


  private discoverHostSubject = new BehaviorSubject<DiscoverHost>(null);
  private zoneSubject = new BehaviorSubject<Zone>(null);
  private startSubject = new BehaviorSubject<boolean>(false);
  private discoveryModeSubject = new BehaviorSubject<string>('');

  discoverHost: Observable<DiscoverHost>;
  zone: Observable<Zone>;
  started: Observable<boolean>;
  discoveryMode: Observable<string>;


  constructor() {
    this.discoverHost = this.discoverHostSubject.asObservable();
    this.zone = this.zoneSubject.asObservable();
    this.started = this.startSubject.asObservable();
    this.discoveryMode = this.discoveryModeSubject.asObservable();
  }

  public setZone(zone: Zone): void {
    this.zoneSubject.next(zone);
  }

  public setDiscoverHost(discoverHost: DiscoverHost): void {
    this.discoverHostSubject.next(discoverHost);
  }

  public setStarted(isStarted: boolean): void {
    this.startSubject.next(isStarted);
  }

  public setDiscoveryMode(mode: string): void {
    this.discoveryModeSubject.next(mode);
  }
}
