// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.maps.geolocation;

import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.maps.geolocation.models.IpAddressToLocationResult;

/**
 * {@link GeolocationClient} instances are created via the {@link GeolocationClientBuilder}, as shown below.
 * Creating a sync client using a {@link AzureKeyCredential}:
 * <!-- src_embed com.azure.maps.geolocation.sync.builder.key.instantiation -->
 * <pre>
 * &#47;&#47; Authenticates using subscription key
 * AzureKeyCredential keyCredential = new AzureKeyCredential&#40;System.getenv&#40;&quot;SUBSCRIPTION_KEY&quot;&#41;&#41;;
 *
 * &#47;&#47; Creates a client
 * GeolocationClient client = new GeolocationClientBuilder&#40;&#41;
 *     .credential&#40;keyCredential&#41;
 *     .buildClient&#40;&#41;;
 * </pre>
 * <!-- end com.azure.maps.geolocation.sync.builder.key.instantiation -->
 */
@ServiceClient(builder = GeolocationClientBuilder.class)
public final class GeolocationClient {
    private final GeolocationAsyncClient asyncClient;

    /**
     * Initializes an instance of GeolocationClient client.
     *
     * @param asyncClient the service client implementation.
     */
    GeolocationClient(GeolocationAsyncClient asyncClient) {
        this.asyncClient = asyncClient;
    }

    /**
     * Get Location
     *
     * <!-- src_embed com.azure.maps.geolocation.sync.get_ip_to_location -->
     * <pre>
     * client.getLocation&#40;&quot;131.107.0.89&quot;&#41;;
     * </pre>
     * <!-- end com.azure.maps.geolocation.sync.get_ip_to_location -->
     *
     * **Applies to**: S0 and S1 pricing tiers.
     *
     * <p>This service will return the ISO country code for the provided IP address. Developers can use this information
     * to block or alter certain content based on geographical locations where the application is being viewed from.
     *
     * @param ipAddress The IP address. Both IPv4 and IPv6 are allowed.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return this object is returned from a successful call to IP Address to country/region API.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public IpAddressToLocationResult getLocation(String ipAddress) {
        return this.asyncClient.getLocation(ipAddress).block();
    }

    /**
     * Get Location
     *
     * <!-- src_embed com.azure.maps.geolocation.sync.get_ip_to_location -->
     * <pre>
     * client.getLocation&#40;&quot;131.107.0.89&quot;&#41;;
     * </pre>
     * <!-- end com.azure.maps.geolocation.sync.get_ip_to_location -->
     *
     * **Applies to**: S0 and S1 pricing tiers.
     *
     * <p>This service will return the ISO country code for the provided IP address. Developers can use this information
     * to block or alter certain content based on geographical locations where the application is being viewed from.
     *
     * @param context The context to associate with this operation.
     * @param ipAddress The IP address. Both IPv4 and IPv6 are allowed.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return this object is returned from a successful call to IP Address to country/region API.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<IpAddressToLocationResult> getLocationWithResponse(String ipAddress, Context context) {
        return this.asyncClient.getLocationWithResponse(ipAddress, context).block();
    }
}
