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 { FleioId, IBaseFleioObjectModel } from '@fleio-api/base-model/base-fleio-object.model';
import { Observable } from 'rxjs/internal/Observable';
import { IListQueryParams } from '@fleio-api/base-model/list-query-params';
import { FleioObjectsList } from '@fleio-api/fleio-objects-list';
import { ICreditAndInvoicingInfoModel } from '@fleio-api/openstack/billing/model/credit-and-invoicing-info.model';

export class BillingHistoryObjectList<ObjectModelType extends IBaseFleioObjectModel> extends FleioObjectsList<ObjectModelType> {
  // eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle,id-blacklist,id-match
  public estimated_cycle_cost: {
    amount: number;
    usage_id: FleioId;
  };
  // eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle, id-blacklist, id-match
  public credit_and_invoicing_info: ICreditAndInvoicingInfoModel;
  latest_data_from?: Date;
  available_services?: Array<Record<string, any>>;
}

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

  list(queryParams: IListQueryParams = {}, action: string = null): Observable<BillingHistoryObjectList<IServiceDynamicUsageModel>> {
    const listResult = super.list(queryParams, action);
    return listResult as Observable<BillingHistoryObjectList<IServiceDynamicUsageModel>>;
  }
}
