# frozen_string_literal: true

# Generated by forge 1.0.0 from NovaPay Payout API 1.0.0 (spec.yaml).
# Optional helpers for endpoints found in the spec but outside the Provider::BaseService contract.
# Kept out of NovapayService on purpose: the service exposes only the four contract methods.

require_relative 'novapay_service'

module Provider
  class NovapayExtras < NovapayService
    def cancel_request(operation)
      response = client.post("#{BASE_URL}/payouts/#{operation.provider_operation_key}/cancel", headers: auth_headers)
      return apply_status(operation, response.body['status']) if response.status == 200

      failure(http_symbol(response.status), "provider.#{error_code_for(response)}")
    end

    def fetch_balance
      response = client.get("#{BASE_URL}/balance", headers: auth_headers)
      return failure(http_symbol(response.status), "provider.#{error_code_for(response)}") unless response.status == 200

      success(balance: response.body['balance'], currency: response.body['currency'], hold: response.body['hold'])
    end
  end
end
