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

package com.azure.resourcemanager.orbital.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
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.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.Put;
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.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
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.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.orbital.fluent.SpacecraftsClient;
import com.azure.resourcemanager.orbital.fluent.models.AvailableContactsInner;
import com.azure.resourcemanager.orbital.fluent.models.SpacecraftInner;
import com.azure.resourcemanager.orbital.models.AvailableContactsListResult;
import com.azure.resourcemanager.orbital.models.ContactParameters;
import com.azure.resourcemanager.orbital.models.SpacecraftListResult;
import com.azure.resourcemanager.orbital.models.TagsObject;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for AzureOrbitalSpacecrafts to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureOrbitalSpacecra")
    public interface SpacecraftsService {
        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.Orbital/spacecrafts")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SpacecraftListResult>> list(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$skiptoken") String skiptoken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/spacecrafts")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SpacecraftListResult>> listByResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$skiptoken") String skiptoken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/spacecrafts/{spacecraftName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SpacecraftInner>> getByResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("spacecraftName") String spacecraftName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/spacecrafts/{spacecraftName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("spacecraftName") String spacecraftName,
            @BodyParam("application/json") SpacecraftInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/spacecrafts/{spacecraftName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("spacecraftName") String spacecraftName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/spacecrafts/{spacecraftName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> updateTags(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("spacecraftName") String spacecraftName,
            @BodyParam("application/json") TagsObject parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/spacecrafts/{spacecraftName}/listAvailableContacts")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> listAvailableContacts(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("spacecraftName") String spacecraftName,
            @BodyParam("application/json") ContactParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SpacecraftListResult>> listBySubscriptionNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SpacecraftListResult>> listNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("{nextLink}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<AvailableContactsListResult>> listAvailableContactsNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Returns list of spacecrafts by subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listSinglePageAsync(String skiptoken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            skiptoken,
                            accept,
                            context))
            .<PagedResponse<SpacecraftInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Returns list of spacecrafts by subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listSinglePageAsync(String skiptoken, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                skiptoken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Returns list of spacecrafts by subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SpacecraftInner> listAsync(String skiptoken) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(skiptoken), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of spacecrafts by subscription.
     *
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SpacecraftInner> listAsync() {
        final String skiptoken = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(skiptoken), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of spacecrafts by subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SpacecraftInner> listAsync(String skiptoken, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(skiptoken, context),
            nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns list of spacecrafts by subscription.
     *
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SpacecraftInner> list() {
        final String skiptoken = null;
        return new PagedIterable<>(listAsync(skiptoken));
    }

    /**
     * Returns list of spacecrafts by subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SpacecraftInner> list(String skiptoken, Context context) {
        return new PagedIterable<>(listAsync(skiptoken, context));
    }

    /**
     * Returns list of spacecrafts by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, String skiptoken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            skiptoken,
                            accept,
                            context))
            .<PagedResponse<SpacecraftInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Returns list of spacecrafts by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, String skiptoken, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                skiptoken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Returns list of spacecrafts by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SpacecraftInner> listByResourceGroupAsync(String resourceGroupName, String skiptoken) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, skiptoken),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of spacecrafts by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SpacecraftInner> listByResourceGroupAsync(String resourceGroupName) {
        final String skiptoken = null;
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, skiptoken),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of spacecrafts by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SpacecraftInner> listByResourceGroupAsync(
        String resourceGroupName, String skiptoken, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, skiptoken, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns list of spacecrafts by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SpacecraftInner> listByResourceGroup(String resourceGroupName) {
        final String skiptoken = null;
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, skiptoken));
    }

    /**
     * Returns list of spacecrafts by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListSpacecrafts API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SpacecraftInner> listByResourceGroup(
        String resourceGroupName, String skiptoken, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, skiptoken, context));
    }

    /**
     * Gets the specified spacecraft in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 specified spacecraft in a specified resource group along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SpacecraftInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String spacecraftName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            spacecraftName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the specified spacecraft in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 specified spacecraft in a specified resource group along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SpacecraftInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String spacecraftName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                spacecraftName,
                accept,
                context);
    }

    /**
     * Gets the specified spacecraft in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 specified spacecraft in a specified resource group on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SpacecraftInner> getByResourceGroupAsync(String resourceGroupName, String spacecraftName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, spacecraftName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the specified spacecraft in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 specified spacecraft in a specified resource group along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SpacecraftInner> getByResourceGroupWithResponse(
        String resourceGroupName, String spacecraftName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, spacecraftName, context).block();
    }

    /**
     * Gets the specified spacecraft in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 specified spacecraft in a specified resource group.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SpacecraftInner getByResourceGroup(String resourceGroupName, String spacecraftName) {
        return getByResourceGroupWithResponse(resourceGroupName, spacecraftName, Context.NONE).getValue();
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 customer creates a spacecraft resource to schedule a contact along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            spacecraftName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 customer creates a spacecraft resource to schedule a contact along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                spacecraftName,
                parameters,
                accept,
                context);
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 {@link PollerFlux} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<SpacecraftInner>, SpacecraftInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, spacecraftName, parameters);
        return this
            .client
            .<SpacecraftInner, SpacecraftInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                SpacecraftInner.class,
                SpacecraftInner.class,
                this.client.getContext());
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 {@link PollerFlux} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<SpacecraftInner>, SpacecraftInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, spacecraftName, parameters, context);
        return this
            .client
            .<SpacecraftInner, SpacecraftInner>getLroResult(
                mono, this.client.getHttpPipeline(), SpacecraftInner.class, SpacecraftInner.class, context);
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 {@link SyncPoller} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<SpacecraftInner>, SpacecraftInner> beginCreateOrUpdate(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters) {
        return this.beginCreateOrUpdateAsync(resourceGroupName, spacecraftName, parameters).getSyncPoller();
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 {@link SyncPoller} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<SpacecraftInner>, SpacecraftInner> beginCreateOrUpdate(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters, Context context) {
        return this.beginCreateOrUpdateAsync(resourceGroupName, spacecraftName, parameters, context).getSyncPoller();
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 customer creates a spacecraft resource to schedule a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SpacecraftInner> createOrUpdateAsync(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters) {
        return beginCreateOrUpdateAsync(resourceGroupName, spacecraftName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 customer creates a spacecraft resource to schedule a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SpacecraftInner> createOrUpdateAsync(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters, Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, spacecraftName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SpacecraftInner createOrUpdate(String resourceGroupName, String spacecraftName, SpacecraftInner parameters) {
        return createOrUpdateAsync(resourceGroupName, spacecraftName, parameters).block();
    }

    /**
     * Creates or updates a spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the created spacecraft.
     * @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 customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SpacecraftInner createOrUpdate(
        String resourceGroupName, String spacecraftName, SpacecraftInner parameters, Context context) {
        return createOrUpdateAsync(resourceGroupName, spacecraftName, parameters, context).block();
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(String resourceGroupName, String spacecraftName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            spacecraftName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String spacecraftName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                spacecraftName,
                accept,
                context);
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(String resourceGroupName, String spacecraftName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, spacecraftName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String spacecraftName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, spacecraftName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(String resourceGroupName, String spacecraftName) {
        return this.beginDeleteAsync(resourceGroupName, spacecraftName).getSyncPoller();
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String spacecraftName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, spacecraftName, context).getSyncPoller();
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String spacecraftName) {
        return beginDeleteAsync(resourceGroupName, spacecraftName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String spacecraftName, Context context) {
        return beginDeleteAsync(resourceGroupName, spacecraftName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String spacecraftName) {
        deleteAsync(resourceGroupName, spacecraftName).block();
    }

    /**
     * Deletes a specified spacecraft resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String spacecraftName, Context context) {
        deleteAsync(resourceGroupName, spacecraftName, context).block();
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 customer creates a spacecraft resource to schedule a contact along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateTagsWithResponseAsync(
        String resourceGroupName, String spacecraftName, TagsObject parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .updateTags(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            spacecraftName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 customer creates a spacecraft resource to schedule a contact along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateTagsWithResponseAsync(
        String resourceGroupName, String spacecraftName, TagsObject parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .updateTags(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                spacecraftName,
                parameters,
                accept,
                context);
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 {@link PollerFlux} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<SpacecraftInner>, SpacecraftInner> beginUpdateTagsAsync(
        String resourceGroupName, String spacecraftName, TagsObject parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateTagsWithResponseAsync(resourceGroupName, spacecraftName, parameters);
        return this
            .client
            .<SpacecraftInner, SpacecraftInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                SpacecraftInner.class,
                SpacecraftInner.class,
                this.client.getContext());
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 {@link PollerFlux} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<SpacecraftInner>, SpacecraftInner> beginUpdateTagsAsync(
        String resourceGroupName, String spacecraftName, TagsObject parameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateTagsWithResponseAsync(resourceGroupName, spacecraftName, parameters, context);
        return this
            .client
            .<SpacecraftInner, SpacecraftInner>getLroResult(
                mono, this.client.getHttpPipeline(), SpacecraftInner.class, SpacecraftInner.class, context);
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 {@link SyncPoller} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<SpacecraftInner>, SpacecraftInner> beginUpdateTags(
        String resourceGroupName, String spacecraftName, TagsObject parameters) {
        return this.beginUpdateTagsAsync(resourceGroupName, spacecraftName, parameters).getSyncPoller();
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 {@link SyncPoller} for polling of customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<SpacecraftInner>, SpacecraftInner> beginUpdateTags(
        String resourceGroupName, String spacecraftName, TagsObject parameters, Context context) {
        return this.beginUpdateTagsAsync(resourceGroupName, spacecraftName, parameters, context).getSyncPoller();
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 customer creates a spacecraft resource to schedule a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SpacecraftInner> updateTagsAsync(
        String resourceGroupName, String spacecraftName, TagsObject parameters) {
        return beginUpdateTagsAsync(resourceGroupName, spacecraftName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 customer creates a spacecraft resource to schedule a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SpacecraftInner> updateTagsAsync(
        String resourceGroupName, String spacecraftName, TagsObject parameters, Context context) {
        return beginUpdateTagsAsync(resourceGroupName, spacecraftName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SpacecraftInner updateTags(String resourceGroupName, String spacecraftName, TagsObject parameters) {
        return updateTagsAsync(resourceGroupName, spacecraftName, parameters).block();
    }

    /**
     * Updates the specified spacecraft tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters Parameters supplied to update spacecraft tags.
     * @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 customer creates a spacecraft resource to schedule a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SpacecraftInner updateTags(
        String resourceGroupName, String spacecraftName, TagsObject parameters, Context context) {
        return updateTagsAsync(resourceGroupName, spacecraftName, parameters, context).block();
    }

    /**
     * Returns list of available contacts. A contact is available if the spacecraft is visible from the ground station
     * for more than the minimum viable contact duration provided in the contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the contacts.
     * @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 response for the ListAvailableContacts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AvailableContactsInner>> listAvailableContactsSinglePageAsync(
        String resourceGroupName, String spacecraftName, ContactParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> {
                    Mono<Response<Flux<ByteBuffer>>> mono =
                        service
                            .listAvailableContacts(
                                this.client.getEndpoint(),
                                resourceGroupName,
                                this.client.getSubscriptionId(),
                                this.client.getApiVersion(),
                                spacecraftName,
                                parameters,
                                accept,
                                context)
                            .cache();
                    return Mono
                        .zip(
                            mono,
                            this
                                .client
                                .<AvailableContactsListResult, AvailableContactsListResult>getLroResult(
                                    mono,
                                    this.client.getHttpPipeline(),
                                    AvailableContactsListResult.class,
                                    AvailableContactsListResult.class,
                                    this.client.getContext())
                                .last()
                                .flatMap(this.client::getLroFinalResultOrError));
                })
            .<PagedResponse<AvailableContactsInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getT1().getRequest(),
                        res.getT1().getStatusCode(),
                        res.getT1().getHeaders(),
                        res.getT2().value(),
                        res.getT2().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Returns list of available contacts. A contact is available if the spacecraft is visible from the ground station
     * for more than the minimum viable contact duration provided in the contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the contacts.
     * @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 response for the ListAvailableContacts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AvailableContactsInner>> listAvailableContactsSinglePageAsync(
        String resourceGroupName, String spacecraftName, ContactParameters parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (spacecraftName == null) {
            return Mono.error(new IllegalArgumentException("Parameter spacecraftName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            service
                .listAvailableContacts(
                    this.client.getEndpoint(),
                    resourceGroupName,
                    this.client.getSubscriptionId(),
                    this.client.getApiVersion(),
                    spacecraftName,
                    parameters,
                    accept,
                    context)
                .cache();
        return Mono
            .zip(
                mono,
                this
                    .client
                    .<AvailableContactsListResult, AvailableContactsListResult>getLroResult(
                        mono,
                        this.client.getHttpPipeline(),
                        AvailableContactsListResult.class,
                        AvailableContactsListResult.class,
                        context)
                    .last()
                    .flatMap(this.client::getLroFinalResultOrError))
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getT1().getRequest(),
                        res.getT1().getStatusCode(),
                        res.getT1().getHeaders(),
                        res.getT2().value(),
                        res.getT2().nextLink(),
                        null));
    }

    /**
     * Returns list of available contacts. A contact is available if the spacecraft is visible from the ground station
     * for more than the minimum viable contact duration provided in the contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the contacts.
     * @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 response for the ListAvailableContacts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AvailableContactsInner> listAvailableContactsAsync(
        String resourceGroupName, String spacecraftName, ContactParameters parameters) {
        return new PagedFlux<>(
            () -> listAvailableContactsSinglePageAsync(resourceGroupName, spacecraftName, parameters),
            nextLink -> listAvailableContactsNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of available contacts. A contact is available if the spacecraft is visible from the ground station
     * for more than the minimum viable contact duration provided in the contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the contacts.
     * @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 response for the ListAvailableContacts API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AvailableContactsInner> listAvailableContactsAsync(
        String resourceGroupName, String spacecraftName, ContactParameters parameters, Context context) {
        return new PagedFlux<>(
            () -> listAvailableContactsSinglePageAsync(resourceGroupName, spacecraftName, parameters, context),
            nextLink -> listAvailableContactsNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns list of available contacts. A contact is available if the spacecraft is visible from the ground station
     * for more than the minimum viable contact duration provided in the contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the contacts.
     * @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 response for the ListAvailableContacts API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AvailableContactsInner> listAvailableContacts(
        String resourceGroupName, String spacecraftName, ContactParameters parameters) {
        return new PagedIterable<>(listAvailableContactsAsync(resourceGroupName, spacecraftName, parameters));
    }

    /**
     * Returns list of available contacts. A contact is available if the spacecraft is visible from the ground station
     * for more than the minimum viable contact duration provided in the contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param spacecraftName Spacecraft ID.
     * @param parameters The parameters to provide for the contacts.
     * @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 response for the ListAvailableContacts API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AvailableContactsInner> listAvailableContacts(
        String resourceGroupName, String spacecraftName, ContactParameters parameters, Context context) {
        return new PagedIterable<>(listAvailableContactsAsync(resourceGroupName, spacecraftName, parameters, context));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listBySubscriptionNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<SpacecraftInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listBySubscriptionNextSinglePageAsync(
        String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<SpacecraftInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 response for the ListSpacecrafts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SpacecraftInner>> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 response for the ListAvailableContacts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AvailableContactsInner>> listAvailableContactsNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.listAvailableContactsNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<AvailableContactsInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 response for the ListAvailableContacts API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AvailableContactsInner>> listAvailableContactsNextSinglePageAsync(
        String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listAvailableContactsNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
