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 { IGatewayModel } from '../model/gateway.model';
import { ITransactionActionModel } from '@fleio-api/billing/model/transaction-action.model';

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

  callAction(action: ITransactionActionModel, invoiceId, transactionId, amount=null) {
    const body = {
      invoice: invoiceId,
      transaction: transactionId,
    } as any;
    if (amount) {
      body.amount = amount;
    }
    return this.objectPostAction(action.gateway, action.name, body);
  }
}
