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

export enum DiscoveryStatusType {
  Started = 'Started',
  Stopping = 'Stopping',
  Stopped = 'Stopped'
}

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


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

  private statusSubject = new BehaviorSubject<DiscoveryStatusType>(DiscoveryStatusType.Stopped);

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

  discoveryStatus: Observable<DiscoveryStatusType>;


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

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

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


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

  public setDiscoveryStatus(mode: DiscoveryStatusType) {
    this.statusSubject.next(mode);
  }
}
