import { Injectable } from '@angular/core';
import { ConfigService } from '@shared/config/config.service';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { FleioApiService } from '@fleio-api/fleio-api.service';
import { IExternalBillingUrlResponseModel } from '@fleio-api/core/model/external-billing-url.model';
import { IClientAutoInvoicingSettingsModel } from '@fleio-api/client-user/model/client-auto-invoicing-settings.model';

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

  getExternalBillingUrl(): Observable<IExternalBillingUrlResponseModel> {
    return this.getAction( 'get-external-billing-url/');
  }

  confirmEmail(confirmationCode: string): Observable<any> {
    return this.postAction('confirm-email/', {
      token: confirmationCode
    });
  }

  resendEmailConfirmationMessage(): Observable<any> {
    return this.postAction('resend-confirmation-email/');
  }

  getCreditAutoInvoicingSettings(clientId: string): Observable<IClientAutoInvoicingSettingsModel> {
    return this.getAction('auto-invoicing-settings', {
      client_id: clientId
    });
  }

  setCreditAutoInvoicingSettings(settings): Observable<any> {
    return this.postAction('auto-invoicing-settings', settings);
  }

}
