import { Injectable } from '@angular/core';
import { ConfigService } from '@shared/config/config.service';
import { HttpClient } from '@angular/common/http';
import { IDomainModel } from './model/domain.model';
import { FleioApiService } from '../../fleio-api.service';
import { Observable } from 'rxjs';
import { ISelectDomainOrderOptionsModel } from '@fleio-api/plugins/domains/model/select-domain-order-options.model';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';

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

  getSelectDomainOptions(params): Observable<ISelectDomainOrderOptionsModel> {
    return this.getAction(
      'order-domain/select_domain_options', params
    );
  }

  lookup(lookupMethod: string, domainName: string, skipWhoisCheck = null) {
    const queryParams = {domain_name: domainName} as any;
    if (skipWhoisCheck !== null) {
      queryParams.skip_whois_check = skipWhoisCheck;
    }
    return this.getAction(`order-domain/${lookupMethod}`, queryParams);
  }
}
