import { Injectable } from '@angular/core';
import { ConfigService } from '@shared/config/config.service';
import { FleioApiService } from '../../fleio-api.service';
import { HttpClient } from '@angular/common/http';
import { IServiceDynamicUsageModel } from '../model/service-dynamic-usage.model';
import { Observable } from 'rxjs';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { BillingHistoryObjectList } from '@fleio-api/billing/billing-history/billing-history-api.service';

@Injectable({
  providedIn: 'root'
})
export class ServiceDynamicUsagesApiService extends FleioApiService<IServiceDynamicUsageModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('openstack/billing/usage'));
  }

  getForClient(clientId: FleioId, pageSize: number = undefined): Observable<BillingHistoryObjectList<IServiceDynamicUsageModel>> {
    const queryParams = {
      client_id: clientId,
    } as any;
    if (pageSize) {
      queryParams.page_size = pageSize;
    }
    return this.list(queryParams, 'client') as Observable<BillingHistoryObjectList<IServiceDynamicUsageModel>>;
  }

}
