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

package com.azure.resourcemanager.hybridcontainerservice.implementation;

import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.hybridcontainerservice.fluent.HybridContainerServicesClient;
import com.azure.resourcemanager.hybridcontainerservice.fluent.models.OrchestratorVersionProfileListResultInner;
import com.azure.resourcemanager.hybridcontainerservice.fluent.models.VMSkuListResultInner;
import reactor.core.publisher.Mono;

/** An instance of this class provides access to all the operations defined in HybridContainerServicesClient. */
public final class HybridContainerServicesClientImpl implements HybridContainerServicesClient {
    /** The proxy service used to perform REST calls. */
    private final HybridContainerServicesService service;

    /** The service client containing this operation class. */
    private final HybridContainerServiceImpl client;

    /**
     * Initializes an instance of HybridContainerServicesClientImpl.
     *
     * @param client the instance of the service client containing this operation class.
     */
    HybridContainerServicesClientImpl(HybridContainerServiceImpl client) {
        this.service =
            RestProxy
                .create(HybridContainerServicesService.class, client.getHttpPipeline(), client.getSerializerAdapter());
        this.client = client;
    }

    /**
     * The interface defining all the services for HybridContainerServiceHybridContainerServices to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "HybridContainerServi")
    public interface HybridContainerServicesService {
        @Headers({"Content-Type: application/json"})
        @Get("/{customLocationResourceUri}/providers/Microsoft.HybridContainerService/orchestrators")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<OrchestratorVersionProfileListResultInner>> listOrchestrators(
            @HostParam("$host") String endpoint,
            @PathParam(value = "customLocationResourceUri", encoded = true) String customLocationResourceUri,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{customLocationResourceUri}/providers/Microsoft.HybridContainerService/vmSkus")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<VMSkuListResultInner>> listVMSkus(
            @HostParam("$host") String endpoint,
            @PathParam(value = "customLocationResourceUri", encoded = true) String customLocationResourceUri,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Lists the available orchestrators in a custom location
     *
     * <p>Lists the available orchestrators in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of versions for supported orchestrators along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<OrchestratorVersionProfileListResultInner>> listOrchestratorsWithResponseAsync(
        String customLocationResourceUri) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (customLocationResourceUri == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter customLocationResourceUri is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listOrchestrators(
                            this.client.getEndpoint(),
                            customLocationResourceUri,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Lists the available orchestrators in a custom location
     *
     * <p>Lists the available orchestrators in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of versions for supported orchestrators along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<OrchestratorVersionProfileListResultInner>> listOrchestratorsWithResponseAsync(
        String customLocationResourceUri, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (customLocationResourceUri == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter customLocationResourceUri is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listOrchestrators(
                this.client.getEndpoint(), customLocationResourceUri, this.client.getApiVersion(), accept, context);
    }

    /**
     * Lists the available orchestrators in a custom location
     *
     * <p>Lists the available orchestrators in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of versions for supported orchestrators on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<OrchestratorVersionProfileListResultInner> listOrchestratorsAsync(String customLocationResourceUri) {
        return listOrchestratorsWithResponseAsync(customLocationResourceUri)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Lists the available orchestrators in a custom location
     *
     * <p>Lists the available orchestrators in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of versions for supported orchestrators along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<OrchestratorVersionProfileListResultInner> listOrchestratorsWithResponse(
        String customLocationResourceUri, Context context) {
        return listOrchestratorsWithResponseAsync(customLocationResourceUri, context).block();
    }

    /**
     * Lists the available orchestrators in a custom location
     *
     * <p>Lists the available orchestrators in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of versions for supported orchestrators.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public OrchestratorVersionProfileListResultInner listOrchestrators(String customLocationResourceUri) {
        return listOrchestratorsWithResponse(customLocationResourceUri, Context.NONE).getValue();
    }

    /**
     * Lists the available VM SKUs in a custom location
     *
     * <p>Lists the available VM SKUs in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of supported VM SKUs along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<VMSkuListResultInner>> listVMSkusWithResponseAsync(String customLocationResourceUri) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (customLocationResourceUri == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter customLocationResourceUri is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listVMSkus(
                            this.client.getEndpoint(),
                            customLocationResourceUri,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Lists the available VM SKUs in a custom location
     *
     * <p>Lists the available VM SKUs in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of supported VM SKUs along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<VMSkuListResultInner>> listVMSkusWithResponseAsync(
        String customLocationResourceUri, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (customLocationResourceUri == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter customLocationResourceUri is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listVMSkus(
                this.client.getEndpoint(), customLocationResourceUri, this.client.getApiVersion(), accept, context);
    }

    /**
     * Lists the available VM SKUs in a custom location
     *
     * <p>Lists the available VM SKUs in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of supported VM SKUs on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VMSkuListResultInner> listVMSkusAsync(String customLocationResourceUri) {
        return listVMSkusWithResponseAsync(customLocationResourceUri).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Lists the available VM SKUs in a custom location
     *
     * <p>Lists the available VM SKUs in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of supported VM SKUs along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<VMSkuListResultInner> listVMSkusWithResponse(String customLocationResourceUri, Context context) {
        return listVMSkusWithResponseAsync(customLocationResourceUri, context).block();
    }

    /**
     * Lists the available VM SKUs in a custom location
     *
     * <p>Lists the available VM SKUs in a custom location for HybridAKS.
     *
     * @param customLocationResourceUri The fully qualified Azure Resource manager identifier of the custom location
     *     resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of supported VM SKUs.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VMSkuListResultInner listVMSkus(String customLocationResourceUri) {
        return listVMSkusWithResponse(customLocationResourceUri, Context.NONE).getValue();
    }
}
