import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { RPCService } from '@loafer/ng-rpc/service';
import {
  DiscoveryStartInfo,
  DiscoveryZone,
  DiscoveryHost,
  DiscoveryPort,
  DiscoveryService as M_DiscoveryService,
  Zone,
  Host,
  Port,
  Service,
} from '../model';

@Injectable()
export class DiscoveryService {

  public constructor(
    private rpcService: RPCService,
  ) {

  }

  public start(dsInfo: DiscoveryStartInfo): Observable<DiscoveryStartInfo> {

    return this.rpcService.call('DiscoveryService.startDiscovery', dsInfo);
  }

  public discoverZone(probeID: string, discoveryZone: DiscoveryZone): void {
    this.rpcService.send('DiscoveryService.discoverZone', probeID, discoveryZone);
  }
  public discoverHost(probeID: string, zone: Zone, discoveryHost: DiscoveryHost): void {
    this.rpcService.send('DiscoveryService.discoverHost', probeID, zone, discoveryHost);
  }
  public discoverPort(probeID: string, host: Host, discoveryPort: DiscoveryPort): void {
    this.rpcService.send('DiscoveryService.discoverPort', probeID, host, discoveryPort);
  }
  public discoverService(probeID: string, port: Port, discoveryService: M_DiscoveryService): void {
    this.rpcService.send('DiscoveryService.discoverService', probeID, port, discoveryService);
  }
}
