/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 */

package com.microsoft.azure.cognitiveservices.vision.customvision.prediction.implementation;

import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.DetectImageWithNoStoreOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.DetectImageUrlWithNoStoreOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.DetectImageOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.DetectImageUrlOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.ClassifyImageWithNoStoreOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.ClassifyImageUrlWithNoStoreOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.ClassifyImageOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.ClassifyImageUrlOptionalParameter;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.Predictions;
import com.google.common.base.Joiner;
import com.google.common.reflect.TypeToken;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.CustomVisionErrorException;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.ImagePrediction;
import com.microsoft.azure.cognitiveservices.vision.customvision.prediction.models.ImageUrl;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import java.io.InputStream;
import java.io.IOException;
import java.util.UUID;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Multipart;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.Response;
import rx.functions.Func1;
import rx.Observable;

/**
 * An instance of this class provides access to all the operations defined
 * in Predictions.
 */
public class PredictionsImpl implements Predictions {
    /** The Retrofit service to perform REST calls. */
    private PredictionsService service;
    /** The service client containing this operation class. */
    private CustomVisionPredictionClientImpl client;

    /**
     * Initializes an instance of PredictionsImpl.
     *
     * @param retrofit the Retrofit instance built from a Retrofit Builder.
     * @param client the instance of the service client containing this operation class.
     */
    public PredictionsImpl(Retrofit retrofit, CustomVisionPredictionClientImpl client) {
        this.service = retrofit.create(PredictionsService.class);
        this.client = client;
    }

    /**
     * The interface defining all the services for Predictions to be
     * used by Retrofit to perform actually REST calls.
     */
    interface PredictionsService {
        @Multipart
        @POST("{projectId}/detect/iterations/{publishedName}/image/nostore")
        Observable<Response<ResponseBody>> detectImageWithNoStore(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Part("imageData") RequestBody imageData, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.customvision.prediction.Predictions detectImageUrlWithNoStore" })
        @POST("{projectId}/detect/iterations/{publishedName}/url/nostore")
        Observable<Response<ResponseBody>> detectImageUrlWithNoStore(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Body ImageUrl imageUrl, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

        @Multipart
        @POST("{projectId}/detect/iterations/{publishedName}/image")
        Observable<Response<ResponseBody>> detectImage(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Part("imageData") RequestBody imageData, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.customvision.prediction.Predictions detectImageUrl" })
        @POST("{projectId}/detect/iterations/{publishedName}/url")
        Observable<Response<ResponseBody>> detectImageUrl(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Body ImageUrl imageUrl, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

        @Multipart
        @POST("{projectId}/classify/iterations/{publishedName}/image/nostore")
        Observable<Response<ResponseBody>> classifyImageWithNoStore(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Part("imageData") RequestBody imageData, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.customvision.prediction.Predictions classifyImageUrlWithNoStore" })
        @POST("{projectId}/classify/iterations/{publishedName}/url/nostore")
        Observable<Response<ResponseBody>> classifyImageUrlWithNoStore(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Body ImageUrl imageUrl, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

        @Multipart
        @POST("{projectId}/classify/iterations/{publishedName}/image")
        Observable<Response<ResponseBody>> classifyImage(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Part("imageData") RequestBody imageData, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.customvision.prediction.Predictions classifyImageUrl" })
        @POST("{projectId}/classify/iterations/{publishedName}/url")
        Observable<Response<ResponseBody>> classifyImageUrl(@Path("projectId") UUID projectId, @Path("publishedName") String publishedName, @Query("application") String application, @Header("Prediction-Key") String apiKey, @Header("accept-language") String acceptLanguage, @Body ImageUrl imageUrl, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);

    }


    /**
     * Detect objects in an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param detectImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction detectImageWithNoStore(UUID projectId, String publishedName, byte[] imageData, DetectImageWithNoStoreOptionalParameter detectImageWithNoStoreOptionalParameter) {
        return detectImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, detectImageWithNoStoreOptionalParameter).toBlocking().single().body();
    }

    /**
     * Detect objects in an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param detectImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> detectImageWithNoStoreAsync(UUID projectId, String publishedName, byte[] imageData, DetectImageWithNoStoreOptionalParameter detectImageWithNoStoreOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(detectImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, detectImageWithNoStoreOptionalParameter), serviceCallback);
    }

    /**
     * Detect objects in an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param detectImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> detectImageWithNoStoreAsync(UUID projectId, String publishedName, byte[] imageData, DetectImageWithNoStoreOptionalParameter detectImageWithNoStoreOptionalParameter) {
        return detectImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, detectImageWithNoStoreOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Detect objects in an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param detectImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, DetectImageWithNoStoreOptionalParameter detectImageWithNoStoreOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        final String application = detectImageWithNoStoreOptionalParameter != null ? detectImageWithNoStoreOptionalParameter.application() : null;

        return detectImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, application);
    }

    /**
     * Detect objects in an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        RequestBody imageDataConverted = RequestBody.create(MediaType.parse("multipart/form-data"), imageData);
        return service.detectImageWithNoStore(projectId, publishedName, application, imageDataConverted, this.client.apiKey(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = detectImageWithNoStoreDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> detectImageWithNoStoreDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsDetectImageWithNoStoreParameters detectImageWithNoStore() {
        return new PredictionsDetectImageWithNoStoreParameters(this);
    }

    /**
     * Internal class implementing PredictionsDetectImageWithNoStoreDefinition.
     */
    class PredictionsDetectImageWithNoStoreParameters implements PredictionsDetectImageWithNoStoreDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private byte[] imageData;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsDetectImageWithNoStoreParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsDetectImageWithNoStoreParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsDetectImageWithNoStoreParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsDetectImageWithNoStoreParameters withImageData(byte[] imageData) {
            this.imageData = imageData;
            return this;
        }

        @Override
        public PredictionsDetectImageWithNoStoreParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return detectImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return detectImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }


    /**
     * Detect objects in an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction detectImageUrlWithNoStore(UUID projectId, String publishedName, String url, DetectImageUrlWithNoStoreOptionalParameter detectImageUrlWithNoStoreOptionalParameter) {
        return detectImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, detectImageUrlWithNoStoreOptionalParameter).toBlocking().single().body();
    }

    /**
     * Detect objects in an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> detectImageUrlWithNoStoreAsync(UUID projectId, String publishedName, String url, DetectImageUrlWithNoStoreOptionalParameter detectImageUrlWithNoStoreOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(detectImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, detectImageUrlWithNoStoreOptionalParameter), serviceCallback);
    }

    /**
     * Detect objects in an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> detectImageUrlWithNoStoreAsync(UUID projectId, String publishedName, String url, DetectImageUrlWithNoStoreOptionalParameter detectImageUrlWithNoStoreOptionalParameter) {
        return detectImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, detectImageUrlWithNoStoreOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Detect objects in an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageUrlWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, String url, DetectImageUrlWithNoStoreOptionalParameter detectImageUrlWithNoStoreOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        final String application = detectImageUrlWithNoStoreOptionalParameter != null ? detectImageUrlWithNoStoreOptionalParameter.application() : null;

        return detectImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, application);
    }

    /**
     * Detect objects in an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageUrlWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, String url, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        ImageUrl imageUrl = new ImageUrl();
        imageUrl.withUrl(url);
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        return service.detectImageUrlWithNoStore(projectId, publishedName, application, this.client.apiKey(), this.client.acceptLanguage(), imageUrl, parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = detectImageUrlWithNoStoreDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> detectImageUrlWithNoStoreDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsDetectImageUrlWithNoStoreParameters detectImageUrlWithNoStore() {
        return new PredictionsDetectImageUrlWithNoStoreParameters(this);
    }

    /**
     * Internal class implementing PredictionsDetectImageUrlWithNoStoreDefinition.
     */
    class PredictionsDetectImageUrlWithNoStoreParameters implements PredictionsDetectImageUrlWithNoStoreDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private String url;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsDetectImageUrlWithNoStoreParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsDetectImageUrlWithNoStoreParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsDetectImageUrlWithNoStoreParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsDetectImageUrlWithNoStoreParameters withUrl(String url) {
            this.url = url;
            return this;
        }

        @Override
        public PredictionsDetectImageUrlWithNoStoreParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return detectImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return detectImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }


    /**
     * Detect objects in an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param detectImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction detectImage(UUID projectId, String publishedName, byte[] imageData, DetectImageOptionalParameter detectImageOptionalParameter) {
        return detectImageWithServiceResponseAsync(projectId, publishedName, imageData, detectImageOptionalParameter).toBlocking().single().body();
    }

    /**
     * Detect objects in an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param detectImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> detectImageAsync(UUID projectId, String publishedName, byte[] imageData, DetectImageOptionalParameter detectImageOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(detectImageWithServiceResponseAsync(projectId, publishedName, imageData, detectImageOptionalParameter), serviceCallback);
    }

    /**
     * Detect objects in an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param detectImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> detectImageAsync(UUID projectId, String publishedName, byte[] imageData, DetectImageOptionalParameter detectImageOptionalParameter) {
        return detectImageWithServiceResponseAsync(projectId, publishedName, imageData, detectImageOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Detect objects in an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param detectImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, DetectImageOptionalParameter detectImageOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        final String application = detectImageOptionalParameter != null ? detectImageOptionalParameter.application() : null;

        return detectImageWithServiceResponseAsync(projectId, publishedName, imageData, application);
    }

    /**
     * Detect objects in an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        RequestBody imageDataConverted = RequestBody.create(MediaType.parse("multipart/form-data"), imageData);
        return service.detectImage(projectId, publishedName, application, imageDataConverted, this.client.apiKey(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = detectImageDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> detectImageDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsDetectImageParameters detectImage() {
        return new PredictionsDetectImageParameters(this);
    }

    /**
     * Internal class implementing PredictionsDetectImageDefinition.
     */
    class PredictionsDetectImageParameters implements PredictionsDetectImageDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private byte[] imageData;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsDetectImageParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsDetectImageParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsDetectImageParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsDetectImageParameters withImageData(byte[] imageData) {
            this.imageData = imageData;
            return this;
        }

        @Override
        public PredictionsDetectImageParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return detectImageWithServiceResponseAsync(projectId, publishedName, imageData, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return detectImageWithServiceResponseAsync(projectId, publishedName, imageData, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }


    /**
     * Detect objects in an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction detectImageUrl(UUID projectId, String publishedName, String url, DetectImageUrlOptionalParameter detectImageUrlOptionalParameter) {
        return detectImageUrlWithServiceResponseAsync(projectId, publishedName, url, detectImageUrlOptionalParameter).toBlocking().single().body();
    }

    /**
     * Detect objects in an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> detectImageUrlAsync(UUID projectId, String publishedName, String url, DetectImageUrlOptionalParameter detectImageUrlOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(detectImageUrlWithServiceResponseAsync(projectId, publishedName, url, detectImageUrlOptionalParameter), serviceCallback);
    }

    /**
     * Detect objects in an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> detectImageUrlAsync(UUID projectId, String publishedName, String url, DetectImageUrlOptionalParameter detectImageUrlOptionalParameter) {
        return detectImageUrlWithServiceResponseAsync(projectId, publishedName, url, detectImageUrlOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Detect objects in an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param detectImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageUrlWithServiceResponseAsync(UUID projectId, String publishedName, String url, DetectImageUrlOptionalParameter detectImageUrlOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        final String application = detectImageUrlOptionalParameter != null ? detectImageUrlOptionalParameter.application() : null;

        return detectImageUrlWithServiceResponseAsync(projectId, publishedName, url, application);
    }

    /**
     * Detect objects in an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> detectImageUrlWithServiceResponseAsync(UUID projectId, String publishedName, String url, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        ImageUrl imageUrl = new ImageUrl();
        imageUrl.withUrl(url);
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        return service.detectImageUrl(projectId, publishedName, application, this.client.apiKey(), this.client.acceptLanguage(), imageUrl, parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = detectImageUrlDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> detectImageUrlDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsDetectImageUrlParameters detectImageUrl() {
        return new PredictionsDetectImageUrlParameters(this);
    }

    /**
     * Internal class implementing PredictionsDetectImageUrlDefinition.
     */
    class PredictionsDetectImageUrlParameters implements PredictionsDetectImageUrlDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private String url;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsDetectImageUrlParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsDetectImageUrlParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsDetectImageUrlParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsDetectImageUrlParameters withUrl(String url) {
            this.url = url;
            return this;
        }

        @Override
        public PredictionsDetectImageUrlParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return detectImageUrlWithServiceResponseAsync(projectId, publishedName, url, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return detectImageUrlWithServiceResponseAsync(projectId, publishedName, url, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }


    /**
     * Classify an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param classifyImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction classifyImageWithNoStore(UUID projectId, String publishedName, byte[] imageData, ClassifyImageWithNoStoreOptionalParameter classifyImageWithNoStoreOptionalParameter) {
        return classifyImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, classifyImageWithNoStoreOptionalParameter).toBlocking().single().body();
    }

    /**
     * Classify an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param classifyImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> classifyImageWithNoStoreAsync(UUID projectId, String publishedName, byte[] imageData, ClassifyImageWithNoStoreOptionalParameter classifyImageWithNoStoreOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(classifyImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, classifyImageWithNoStoreOptionalParameter), serviceCallback);
    }

    /**
     * Classify an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param classifyImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> classifyImageWithNoStoreAsync(UUID projectId, String publishedName, byte[] imageData, ClassifyImageWithNoStoreOptionalParameter classifyImageWithNoStoreOptionalParameter) {
        return classifyImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, classifyImageWithNoStoreOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Classify an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param classifyImageWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, ClassifyImageWithNoStoreOptionalParameter classifyImageWithNoStoreOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        final String application = classifyImageWithNoStoreOptionalParameter != null ? classifyImageWithNoStoreOptionalParameter.application() : null;

        return classifyImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, application);
    }

    /**
     * Classify an image without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 0MB.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        RequestBody imageDataConverted = RequestBody.create(MediaType.parse("multipart/form-data"), imageData);
        return service.classifyImageWithNoStore(projectId, publishedName, application, imageDataConverted, this.client.apiKey(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = classifyImageWithNoStoreDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> classifyImageWithNoStoreDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsClassifyImageWithNoStoreParameters classifyImageWithNoStore() {
        return new PredictionsClassifyImageWithNoStoreParameters(this);
    }

    /**
     * Internal class implementing PredictionsClassifyImageWithNoStoreDefinition.
     */
    class PredictionsClassifyImageWithNoStoreParameters implements PredictionsClassifyImageWithNoStoreDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private byte[] imageData;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsClassifyImageWithNoStoreParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsClassifyImageWithNoStoreParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsClassifyImageWithNoStoreParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsClassifyImageWithNoStoreParameters withImageData(byte[] imageData) {
            this.imageData = imageData;
            return this;
        }

        @Override
        public PredictionsClassifyImageWithNoStoreParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return classifyImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return classifyImageWithNoStoreWithServiceResponseAsync(projectId, publishedName, imageData, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }


    /**
     * Classify an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction classifyImageUrlWithNoStore(UUID projectId, String publishedName, String url, ClassifyImageUrlWithNoStoreOptionalParameter classifyImageUrlWithNoStoreOptionalParameter) {
        return classifyImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, classifyImageUrlWithNoStoreOptionalParameter).toBlocking().single().body();
    }

    /**
     * Classify an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> classifyImageUrlWithNoStoreAsync(UUID projectId, String publishedName, String url, ClassifyImageUrlWithNoStoreOptionalParameter classifyImageUrlWithNoStoreOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(classifyImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, classifyImageUrlWithNoStoreOptionalParameter), serviceCallback);
    }

    /**
     * Classify an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> classifyImageUrlWithNoStoreAsync(UUID projectId, String publishedName, String url, ClassifyImageUrlWithNoStoreOptionalParameter classifyImageUrlWithNoStoreOptionalParameter) {
        return classifyImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, classifyImageUrlWithNoStoreOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Classify an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlWithNoStoreOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageUrlWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, String url, ClassifyImageUrlWithNoStoreOptionalParameter classifyImageUrlWithNoStoreOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        final String application = classifyImageUrlWithNoStoreOptionalParameter != null ? classifyImageUrlWithNoStoreOptionalParameter.application() : null;

        return classifyImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, application);
    }

    /**
     * Classify an image url without saving the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageUrlWithNoStoreWithServiceResponseAsync(UUID projectId, String publishedName, String url, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        ImageUrl imageUrl = new ImageUrl();
        imageUrl.withUrl(url);
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        return service.classifyImageUrlWithNoStore(projectId, publishedName, application, this.client.apiKey(), this.client.acceptLanguage(), imageUrl, parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = classifyImageUrlWithNoStoreDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> classifyImageUrlWithNoStoreDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsClassifyImageUrlWithNoStoreParameters classifyImageUrlWithNoStore() {
        return new PredictionsClassifyImageUrlWithNoStoreParameters(this);
    }

    /**
     * Internal class implementing PredictionsClassifyImageUrlWithNoStoreDefinition.
     */
    class PredictionsClassifyImageUrlWithNoStoreParameters implements PredictionsClassifyImageUrlWithNoStoreDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private String url;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsClassifyImageUrlWithNoStoreParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsClassifyImageUrlWithNoStoreParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsClassifyImageUrlWithNoStoreParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsClassifyImageUrlWithNoStoreParameters withUrl(String url) {
            this.url = url;
            return this;
        }

        @Override
        public PredictionsClassifyImageUrlWithNoStoreParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return classifyImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return classifyImageUrlWithNoStoreWithServiceResponseAsync(projectId, publishedName, url, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }


    /**
     * Classify an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param classifyImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction classifyImage(UUID projectId, String publishedName, byte[] imageData, ClassifyImageOptionalParameter classifyImageOptionalParameter) {
        return classifyImageWithServiceResponseAsync(projectId, publishedName, imageData, classifyImageOptionalParameter).toBlocking().single().body();
    }

    /**
     * Classify an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param classifyImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> classifyImageAsync(UUID projectId, String publishedName, byte[] imageData, ClassifyImageOptionalParameter classifyImageOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(classifyImageWithServiceResponseAsync(projectId, publishedName, imageData, classifyImageOptionalParameter), serviceCallback);
    }

    /**
     * Classify an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param classifyImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> classifyImageAsync(UUID projectId, String publishedName, byte[] imageData, ClassifyImageOptionalParameter classifyImageOptionalParameter) {
        return classifyImageWithServiceResponseAsync(projectId, publishedName, imageData, classifyImageOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Classify an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param classifyImageOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, ClassifyImageOptionalParameter classifyImageOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        final String application = classifyImageOptionalParameter != null ? classifyImageOptionalParameter.application() : null;

        return classifyImageWithServiceResponseAsync(projectId, publishedName, imageData, application);
    }

    /**
     * Classify an image and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param imageData Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports images up to 4MB.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageWithServiceResponseAsync(UUID projectId, String publishedName, byte[] imageData, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (imageData == null) {
            throw new IllegalArgumentException("Parameter imageData is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        RequestBody imageDataConverted = RequestBody.create(MediaType.parse("multipart/form-data"), imageData);
        return service.classifyImage(projectId, publishedName, application, imageDataConverted, this.client.apiKey(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = classifyImageDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> classifyImageDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsClassifyImageParameters classifyImage() {
        return new PredictionsClassifyImageParameters(this);
    }

    /**
     * Internal class implementing PredictionsClassifyImageDefinition.
     */
    class PredictionsClassifyImageParameters implements PredictionsClassifyImageDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private byte[] imageData;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsClassifyImageParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsClassifyImageParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsClassifyImageParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsClassifyImageParameters withImageData(byte[] imageData) {
            this.imageData = imageData;
            return this;
        }

        @Override
        public PredictionsClassifyImageParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return classifyImageWithServiceResponseAsync(projectId, publishedName, imageData, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return classifyImageWithServiceResponseAsync(projectId, publishedName, imageData, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }


    /**
     * Classify an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws CustomVisionErrorException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the ImagePrediction object if successful.
     */
    public ImagePrediction classifyImageUrl(UUID projectId, String publishedName, String url, ClassifyImageUrlOptionalParameter classifyImageUrlOptionalParameter) {
        return classifyImageUrlWithServiceResponseAsync(projectId, publishedName, url, classifyImageUrlOptionalParameter).toBlocking().single().body();
    }

    /**
     * Classify an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<ImagePrediction> classifyImageUrlAsync(UUID projectId, String publishedName, String url, ClassifyImageUrlOptionalParameter classifyImageUrlOptionalParameter, final ServiceCallback<ImagePrediction> serviceCallback) {
        return ServiceFuture.fromResponse(classifyImageUrlWithServiceResponseAsync(projectId, publishedName, url, classifyImageUrlOptionalParameter), serviceCallback);
    }

    /**
     * Classify an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ImagePrediction> classifyImageUrlAsync(UUID projectId, String publishedName, String url, ClassifyImageUrlOptionalParameter classifyImageUrlOptionalParameter) {
        return classifyImageUrlWithServiceResponseAsync(projectId, publishedName, url, classifyImageUrlOptionalParameter).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
            @Override
            public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                return response.body();
            }
        });
    }

    /**
     * Classify an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param classifyImageUrlOptionalParameter the object representing the optional parameters to be set before calling this API
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageUrlWithServiceResponseAsync(UUID projectId, String publishedName, String url, ClassifyImageUrlOptionalParameter classifyImageUrlOptionalParameter) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        final String application = classifyImageUrlOptionalParameter != null ? classifyImageUrlOptionalParameter.application() : null;

        return classifyImageUrlWithServiceResponseAsync(projectId, publishedName, url, application);
    }

    /**
     * Classify an image url and saves the result.
     *
     * @param projectId The project id.
     * @param publishedName Specifies the name of the model to evaluate against.
     * @param url Url of the image.
     * @param application Optional. Specifies the name of application using the endpoint.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ImagePrediction object
     */
    public Observable<ServiceResponse<ImagePrediction>> classifyImageUrlWithServiceResponseAsync(UUID projectId, String publishedName, String url, String application) {
        if (this.client.endpoint() == null) {
            throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null.");
        }
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (publishedName == null) {
            throw new IllegalArgumentException("Parameter publishedName is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        if (url == null) {
            throw new IllegalArgumentException("Parameter url is required and cannot be null.");
        }
        ImageUrl imageUrl = new ImageUrl();
        imageUrl.withUrl(url);
        String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint());
        return service.classifyImageUrl(projectId, publishedName, application, this.client.apiKey(), this.client.acceptLanguage(), imageUrl, parameterizedHost, this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ImagePrediction>>>() {
                @Override
                public Observable<ServiceResponse<ImagePrediction>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<ImagePrediction> clientResponse = classifyImageUrlDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<ImagePrediction> classifyImageUrlDelegate(Response<ResponseBody> response) throws CustomVisionErrorException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<ImagePrediction, CustomVisionErrorException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<ImagePrediction>() { }.getType())
                .registerError(CustomVisionErrorException.class)
                .build(response);
    }

    @Override
    public PredictionsClassifyImageUrlParameters classifyImageUrl() {
        return new PredictionsClassifyImageUrlParameters(this);
    }

    /**
     * Internal class implementing PredictionsClassifyImageUrlDefinition.
     */
    class PredictionsClassifyImageUrlParameters implements PredictionsClassifyImageUrlDefinition {
        private PredictionsImpl parent;
        private UUID projectId;
        private String publishedName;
        private String url;
        private String application;

        /**
         * Constructor.
         * @param parent the parent object.
         */
        PredictionsClassifyImageUrlParameters(PredictionsImpl parent) {
            this.parent = parent;
        }

        @Override
        public PredictionsClassifyImageUrlParameters withProjectId(UUID projectId) {
            this.projectId = projectId;
            return this;
        }

        @Override
        public PredictionsClassifyImageUrlParameters withPublishedName(String publishedName) {
            this.publishedName = publishedName;
            return this;
        }

        @Override
        public PredictionsClassifyImageUrlParameters withUrl(String url) {
            this.url = url;
            return this;
        }

        @Override
        public PredictionsClassifyImageUrlParameters withApplication(String application) {
            this.application = application;
            return this;
        }

        @Override
        public ImagePrediction execute() {
        return classifyImageUrlWithServiceResponseAsync(projectId, publishedName, url, application).toBlocking().single().body();
    }

        @Override
        public Observable<ImagePrediction> executeAsync() {
            return classifyImageUrlWithServiceResponseAsync(projectId, publishedName, url, application).map(new Func1<ServiceResponse<ImagePrediction>, ImagePrediction>() {
                @Override
                public ImagePrediction call(ServiceResponse<ImagePrediction> response) {
                    return response.body();
                }
            });
        }
    }

}
