/**
 * OpenAPI Petstore
 * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

package org.openapitools.client;

import java.util.concurrent.ExecutionException;

import io.helidon.common.GenericType;
import io.helidon.common.reactive.Single;
import io.helidon.webclient.WebClientResponse;

/**
 * Implementation of a generic-typed response.
 *
 * @param <T> type of the return value from the generated API method
 */
class ApiResponseBase<T> implements ApiResponse<T> {

  private final Single<WebClientResponse> webClientResponse;
  private final GenericType<T> responseType;

  protected ApiResponseBase(GenericType<T> responseType, Single<WebClientResponse> webClientResponse) {
    this.webClientResponse = webClientResponse;
    this.responseType = responseType;
  }

  @Override
  public Single<WebClientResponse> webClientResponse() {
    return webClientResponse;
  }

  @Override
  public Single<T> result() throws ExecutionException, InterruptedException {
    return webClientResponse.get().content().as(responseType);
  }
}