import { Injectable } from '@angular/core';
import { ConfigService } from '@shared/config/config.service';
import { HttpClient } from '@angular/common/http';
import { FleioApiService } from '@fleio-api/fleio-api.service';
import { ILoadBalancerModel } from '@fleio-api/openstack/load-balancing/model/load-balancer.model';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { Observable } from 'rxjs/internal/Observable';
import { ILBAssociateFloatingIpOptions } from '@fleio-api/openstack/load-balancing/model/lb-associate-floating-ip-options.model';

@Injectable({
  providedIn: 'root',
})
export class LoadBalancersApiService extends FleioApiService<ILoadBalancerModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('openstack/lbaas-load-balancers'));
  }

  associateFloatingIpOptions(loadBalancerId: FleioId): Observable<ILBAssociateFloatingIpOptions> {
    return this.objectGetAction(loadBalancerId, 'associate-floating-ip-options');
  }

  associateFloatingIp(loadBalancerId: FleioId, params: any): Observable<any> {
    return this.objectPostAction(loadBalancerId, 'associate-floating-ip', params);
  }

  getPrice(data): Observable<any> {
    return this.getAction('get_price', data);
  }
}
