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

package com.azure.resourcemanager.support.implementation;

import com.azure.core.annotation.BodyParam;
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.support.fluent.SupportTicketsClient;
import com.azure.resourcemanager.support.fluent.models.CheckNameAvailabilityOutputInner;
import com.azure.resourcemanager.support.fluent.models.SupportTicketDetailsInner;
import com.azure.resourcemanager.support.models.CheckNameAvailabilityInput;
import com.azure.resourcemanager.support.models.SupportTicketsListResult;
import com.azure.resourcemanager.support.models.UpdateSupportTicket;
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 SupportTicketsClient. */
public final class SupportTicketsClientImpl implements SupportTicketsClient {
    /** The proxy service used to perform REST calls. */
    private final SupportTicketsService service;

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

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

    /**
     * The interface defining all the services for MicrosoftSupportSupportTickets to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "MicrosoftSupportSupp")
    public interface SupportTicketsService {
        @Headers({"Content-Type: application/json"})
        @Post("/subscriptions/{subscriptionId}/providers/Microsoft.Support/checkNameAvailability")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CheckNameAvailabilityOutputInner>> checkNameAvailability(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CheckNameAvailabilityInput checkNameAvailabilityInput,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SupportTicketsListResult>> list(
            @HostParam("$host") String endpoint,
            @QueryParam("$top") Integer top,
            @QueryParam("$filter") String filter,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets/{supportTicketName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SupportTicketDetailsInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("supportTicketName") String supportTicketName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets/{supportTicketName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SupportTicketDetailsInner>> update(
            @HostParam("$host") String endpoint,
            @PathParam("supportTicketName") String supportTicketName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") UpdateSupportTicket updateSupportTicket,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put("/subscriptions/{subscriptionId}/providers/Microsoft.Support/supportTickets/{supportTicketName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> create(
            @HostParam("$host") String endpoint,
            @PathParam("supportTicketName") String supportTicketName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") SupportTicketDetailsInner createSupportTicketParameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Check the availability of a resource name. This API should be used to check the uniqueness of the name for
     * support ticket creation for the selected subscription.
     *
     * @param checkNameAvailabilityInput Input to check.
     * @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 output of check name availability API along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityOutputInner>> checkNameAvailabilityWithResponseAsync(
        CheckNameAvailabilityInput checkNameAvailabilityInput) {
        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."));
        }
        if (checkNameAvailabilityInput == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter checkNameAvailabilityInput is required and cannot be null."));
        } else {
            checkNameAvailabilityInput.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .checkNameAvailability(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            checkNameAvailabilityInput,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Check the availability of a resource name. This API should be used to check the uniqueness of the name for
     * support ticket creation for the selected subscription.
     *
     * @param checkNameAvailabilityInput Input to check.
     * @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 output of check name availability API along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityOutputInner>> checkNameAvailabilityWithResponseAsync(
        CheckNameAvailabilityInput checkNameAvailabilityInput, 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."));
        }
        if (checkNameAvailabilityInput == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter checkNameAvailabilityInput is required and cannot be null."));
        } else {
            checkNameAvailabilityInput.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .checkNameAvailability(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                checkNameAvailabilityInput,
                accept,
                context);
    }

    /**
     * Check the availability of a resource name. This API should be used to check the uniqueness of the name for
     * support ticket creation for the selected subscription.
     *
     * @param checkNameAvailabilityInput Input to check.
     * @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 output of check name availability API on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CheckNameAvailabilityOutputInner> checkNameAvailabilityAsync(
        CheckNameAvailabilityInput checkNameAvailabilityInput) {
        return checkNameAvailabilityWithResponseAsync(checkNameAvailabilityInput)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Check the availability of a resource name. This API should be used to check the uniqueness of the name for
     * support ticket creation for the selected subscription.
     *
     * @param checkNameAvailabilityInput Input to check.
     * @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 output of check name availability API along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CheckNameAvailabilityOutputInner> checkNameAvailabilityWithResponse(
        CheckNameAvailabilityInput checkNameAvailabilityInput, Context context) {
        return checkNameAvailabilityWithResponseAsync(checkNameAvailabilityInput, context).block();
    }

    /**
     * Check the availability of a resource name. This API should be used to check the uniqueness of the name for
     * support ticket creation for the selected subscription.
     *
     * @param checkNameAvailabilityInput Input to check.
     * @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 output of check name availability API.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CheckNameAvailabilityOutputInner checkNameAvailability(
        CheckNameAvailabilityInput checkNameAvailabilityInput) {
        return checkNameAvailabilityWithResponse(checkNameAvailabilityInput, Context.NONE).getValue();
    }

    /**
     * Lists all the support tickets for an Azure subscription. You can also filter the support tickets by _Status_,
     * _CreatedDate_, _ServiceId_, and _ProblemClassificationId_ using the $filter parameter. Output will be a paged
     * result with _nextLink_, using which you can retrieve the next set of support tickets.
     * &lt;br/&gt;&lt;br/&gt;Support ticket data is available for 18 months after ticket creation. If a ticket was
     * created more than 18 months ago, a request for data might cause an error.
     *
     * @param top The number of values to return in the collection. Default is 25 and max is 100.
     * @param filter The filter to apply on the operation. We support 'odata v4.0' filter semantics. [Learn
     *     more](https://docs.microsoft.com/odata/concepts/queryoptions-overview). _Status_, _ServiceId_, and
     *     _ProblemClassificationId_ filters can only be used with Equals ('eq') operator. For _CreatedDate_ filter, the
     *     supported operators are Greater Than ('gt') and Greater Than or Equals ('ge'). When using both filters,
     *     combine them using the logical 'AND'.
     * @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 object that represents a collection of SupportTicket resources along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SupportTicketDetailsInner>> listSinglePageAsync(Integer top, String filter) {
        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(),
                            top,
                            filter,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<SupportTicketDetailsInner>>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()));
    }

    /**
     * Lists all the support tickets for an Azure subscription. You can also filter the support tickets by _Status_,
     * _CreatedDate_, _ServiceId_, and _ProblemClassificationId_ using the $filter parameter. Output will be a paged
     * result with _nextLink_, using which you can retrieve the next set of support tickets.
     * &lt;br/&gt;&lt;br/&gt;Support ticket data is available for 18 months after ticket creation. If a ticket was
     * created more than 18 months ago, a request for data might cause an error.
     *
     * @param top The number of values to return in the collection. Default is 25 and max is 100.
     * @param filter The filter to apply on the operation. We support 'odata v4.0' filter semantics. [Learn
     *     more](https://docs.microsoft.com/odata/concepts/queryoptions-overview). _Status_, _ServiceId_, and
     *     _ProblemClassificationId_ filters can only be used with Equals ('eq') operator. For _CreatedDate_ filter, the
     *     supported operators are Greater Than ('gt') and Greater Than or Equals ('ge'). When using both filters,
     *     combine them using the logical 'AND'.
     * @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 object that represents a collection of SupportTicket resources along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SupportTicketDetailsInner>> listSinglePageAsync(
        Integer top, String filter, 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(),
                top,
                filter,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists all the support tickets for an Azure subscription. You can also filter the support tickets by _Status_,
     * _CreatedDate_, _ServiceId_, and _ProblemClassificationId_ using the $filter parameter. Output will be a paged
     * result with _nextLink_, using which you can retrieve the next set of support tickets.
     * &lt;br/&gt;&lt;br/&gt;Support ticket data is available for 18 months after ticket creation. If a ticket was
     * created more than 18 months ago, a request for data might cause an error.
     *
     * @param top The number of values to return in the collection. Default is 25 and max is 100.
     * @param filter The filter to apply on the operation. We support 'odata v4.0' filter semantics. [Learn
     *     more](https://docs.microsoft.com/odata/concepts/queryoptions-overview). _Status_, _ServiceId_, and
     *     _ProblemClassificationId_ filters can only be used with Equals ('eq') operator. For _CreatedDate_ filter, the
     *     supported operators are Greater Than ('gt') and Greater Than or Equals ('ge'). When using both filters,
     *     combine them using the logical 'AND'.
     * @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 object that represents a collection of SupportTicket resources as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SupportTicketDetailsInner> listAsync(Integer top, String filter) {
        return new PagedFlux<>(() -> listSinglePageAsync(top, filter), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists all the support tickets for an Azure subscription. You can also filter the support tickets by _Status_,
     * _CreatedDate_, _ServiceId_, and _ProblemClassificationId_ using the $filter parameter. Output will be a paged
     * result with _nextLink_, using which you can retrieve the next set of support tickets.
     * &lt;br/&gt;&lt;br/&gt;Support ticket data is available for 18 months after ticket creation. If a ticket was
     * created more than 18 months ago, a request for data might cause an error.
     *
     * @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 object that represents a collection of SupportTicket resources as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SupportTicketDetailsInner> listAsync() {
        final Integer top = null;
        final String filter = null;
        return new PagedFlux<>(() -> listSinglePageAsync(top, filter), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists all the support tickets for an Azure subscription. You can also filter the support tickets by _Status_,
     * _CreatedDate_, _ServiceId_, and _ProblemClassificationId_ using the $filter parameter. Output will be a paged
     * result with _nextLink_, using which you can retrieve the next set of support tickets.
     * &lt;br/&gt;&lt;br/&gt;Support ticket data is available for 18 months after ticket creation. If a ticket was
     * created more than 18 months ago, a request for data might cause an error.
     *
     * @param top The number of values to return in the collection. Default is 25 and max is 100.
     * @param filter The filter to apply on the operation. We support 'odata v4.0' filter semantics. [Learn
     *     more](https://docs.microsoft.com/odata/concepts/queryoptions-overview). _Status_, _ServiceId_, and
     *     _ProblemClassificationId_ filters can only be used with Equals ('eq') operator. For _CreatedDate_ filter, the
     *     supported operators are Greater Than ('gt') and Greater Than or Equals ('ge'). When using both filters,
     *     combine them using the logical 'AND'.
     * @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 object that represents a collection of SupportTicket resources as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SupportTicketDetailsInner> listAsync(Integer top, String filter, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(top, filter, context), nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists all the support tickets for an Azure subscription. You can also filter the support tickets by _Status_,
     * _CreatedDate_, _ServiceId_, and _ProblemClassificationId_ using the $filter parameter. Output will be a paged
     * result with _nextLink_, using which you can retrieve the next set of support tickets.
     * &lt;br/&gt;&lt;br/&gt;Support ticket data is available for 18 months after ticket creation. If a ticket was
     * created more than 18 months ago, a request for data might cause an error.
     *
     * @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 object that represents a collection of SupportTicket resources as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SupportTicketDetailsInner> list() {
        final Integer top = null;
        final String filter = null;
        return new PagedIterable<>(listAsync(top, filter));
    }

    /**
     * Lists all the support tickets for an Azure subscription. You can also filter the support tickets by _Status_,
     * _CreatedDate_, _ServiceId_, and _ProblemClassificationId_ using the $filter parameter. Output will be a paged
     * result with _nextLink_, using which you can retrieve the next set of support tickets.
     * &lt;br/&gt;&lt;br/&gt;Support ticket data is available for 18 months after ticket creation. If a ticket was
     * created more than 18 months ago, a request for data might cause an error.
     *
     * @param top The number of values to return in the collection. Default is 25 and max is 100.
     * @param filter The filter to apply on the operation. We support 'odata v4.0' filter semantics. [Learn
     *     more](https://docs.microsoft.com/odata/concepts/queryoptions-overview). _Status_, _ServiceId_, and
     *     _ProblemClassificationId_ filters can only be used with Equals ('eq') operator. For _CreatedDate_ filter, the
     *     supported operators are Greater Than ('gt') and Greater Than or Equals ('ge'). When using both filters,
     *     combine them using the logical 'AND'.
     * @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 object that represents a collection of SupportTicket resources as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SupportTicketDetailsInner> list(Integer top, String filter, Context context) {
        return new PagedIterable<>(listAsync(top, filter, context));
    }

    /**
     * Get ticket details for an Azure subscription. Support ticket data is available for 18 months after ticket
     * creation. If a ticket was created more than 18 months ago, a request for data might cause an error.
     *
     * @param supportTicketName Support ticket name.
     * @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 ticket details for an Azure subscription along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SupportTicketDetailsInner>> getWithResponseAsync(String supportTicketName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (supportTicketName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter supportTicketName 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
                        .get(
                            this.client.getEndpoint(),
                            supportTicketName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get ticket details for an Azure subscription. Support ticket data is available for 18 months after ticket
     * creation. If a ticket was created more than 18 months ago, a request for data might cause an error.
     *
     * @param supportTicketName Support ticket name.
     * @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 ticket details for an Azure subscription along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SupportTicketDetailsInner>> getWithResponseAsync(String supportTicketName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (supportTicketName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter supportTicketName 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
            .get(
                this.client.getEndpoint(),
                supportTicketName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Get ticket details for an Azure subscription. Support ticket data is available for 18 months after ticket
     * creation. If a ticket was created more than 18 months ago, a request for data might cause an error.
     *
     * @param supportTicketName Support ticket name.
     * @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 ticket details for an Azure subscription on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SupportTicketDetailsInner> getAsync(String supportTicketName) {
        return getWithResponseAsync(supportTicketName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get ticket details for an Azure subscription. Support ticket data is available for 18 months after ticket
     * creation. If a ticket was created more than 18 months ago, a request for data might cause an error.
     *
     * @param supportTicketName Support ticket name.
     * @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 ticket details for an Azure subscription along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SupportTicketDetailsInner> getWithResponse(String supportTicketName, Context context) {
        return getWithResponseAsync(supportTicketName, context).block();
    }

    /**
     * Get ticket details for an Azure subscription. Support ticket data is available for 18 months after ticket
     * creation. If a ticket was created more than 18 months ago, a request for data might cause an error.
     *
     * @param supportTicketName Support ticket name.
     * @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 ticket details for an Azure subscription.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SupportTicketDetailsInner get(String supportTicketName) {
        return getWithResponse(supportTicketName, Context.NONE).getValue();
    }

    /**
     * This API allows you to update the severity level, ticket status, and your contact information in the support
     * ticket.&lt;br/&gt;&lt;br/&gt;Note: The severity levels cannot be changed if a support ticket is actively being
     * worked upon by an Azure support engineer. In such a case, contact your support engineer to request severity
     * update by adding a new communication using the Communications API.&lt;br/&gt;&lt;br/&gt;Changing the ticket
     * status to _closed_ is allowed only on an unassigned case. When an engineer is actively working on the ticket,
     * send your ticket closure request by sending a note to your engineer.
     *
     * @param supportTicketName Support ticket name.
     * @param updateSupportTicket UpdateSupportTicket object.
     * @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 object that represents SupportTicketDetails resource along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SupportTicketDetailsInner>> updateWithResponseAsync(
        String supportTicketName, UpdateSupportTicket updateSupportTicket) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (supportTicketName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter supportTicketName 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 (updateSupportTicket == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter updateSupportTicket is required and cannot be null."));
        } else {
            updateSupportTicket.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            supportTicketName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            updateSupportTicket,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * This API allows you to update the severity level, ticket status, and your contact information in the support
     * ticket.&lt;br/&gt;&lt;br/&gt;Note: The severity levels cannot be changed if a support ticket is actively being
     * worked upon by an Azure support engineer. In such a case, contact your support engineer to request severity
     * update by adding a new communication using the Communications API.&lt;br/&gt;&lt;br/&gt;Changing the ticket
     * status to _closed_ is allowed only on an unassigned case. When an engineer is actively working on the ticket,
     * send your ticket closure request by sending a note to your engineer.
     *
     * @param supportTicketName Support ticket name.
     * @param updateSupportTicket UpdateSupportTicket object.
     * @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 object that represents SupportTicketDetails resource along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SupportTicketDetailsInner>> updateWithResponseAsync(
        String supportTicketName, UpdateSupportTicket updateSupportTicket, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (supportTicketName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter supportTicketName 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 (updateSupportTicket == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter updateSupportTicket is required and cannot be null."));
        } else {
            updateSupportTicket.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                supportTicketName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                updateSupportTicket,
                accept,
                context);
    }

    /**
     * This API allows you to update the severity level, ticket status, and your contact information in the support
     * ticket.&lt;br/&gt;&lt;br/&gt;Note: The severity levels cannot be changed if a support ticket is actively being
     * worked upon by an Azure support engineer. In such a case, contact your support engineer to request severity
     * update by adding a new communication using the Communications API.&lt;br/&gt;&lt;br/&gt;Changing the ticket
     * status to _closed_ is allowed only on an unassigned case. When an engineer is actively working on the ticket,
     * send your ticket closure request by sending a note to your engineer.
     *
     * @param supportTicketName Support ticket name.
     * @param updateSupportTicket UpdateSupportTicket object.
     * @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 object that represents SupportTicketDetails resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SupportTicketDetailsInner> updateAsync(
        String supportTicketName, UpdateSupportTicket updateSupportTicket) {
        return updateWithResponseAsync(supportTicketName, updateSupportTicket)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * This API allows you to update the severity level, ticket status, and your contact information in the support
     * ticket.&lt;br/&gt;&lt;br/&gt;Note: The severity levels cannot be changed if a support ticket is actively being
     * worked upon by an Azure support engineer. In such a case, contact your support engineer to request severity
     * update by adding a new communication using the Communications API.&lt;br/&gt;&lt;br/&gt;Changing the ticket
     * status to _closed_ is allowed only on an unassigned case. When an engineer is actively working on the ticket,
     * send your ticket closure request by sending a note to your engineer.
     *
     * @param supportTicketName Support ticket name.
     * @param updateSupportTicket UpdateSupportTicket object.
     * @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 object that represents SupportTicketDetails resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SupportTicketDetailsInner> updateWithResponse(
        String supportTicketName, UpdateSupportTicket updateSupportTicket, Context context) {
        return updateWithResponseAsync(supportTicketName, updateSupportTicket, context).block();
    }

    /**
     * This API allows you to update the severity level, ticket status, and your contact information in the support
     * ticket.&lt;br/&gt;&lt;br/&gt;Note: The severity levels cannot be changed if a support ticket is actively being
     * worked upon by an Azure support engineer. In such a case, contact your support engineer to request severity
     * update by adding a new communication using the Communications API.&lt;br/&gt;&lt;br/&gt;Changing the ticket
     * status to _closed_ is allowed only on an unassigned case. When an engineer is actively working on the ticket,
     * send your ticket closure request by sending a note to your engineer.
     *
     * @param supportTicketName Support ticket name.
     * @param updateSupportTicket UpdateSupportTicket object.
     * @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 object that represents SupportTicketDetails resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SupportTicketDetailsInner update(String supportTicketName, UpdateSupportTicket updateSupportTicket) {
        return updateWithResponse(supportTicketName, updateSupportTicket, Context.NONE).getValue();
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (supportTicketName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter supportTicketName 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 (createSupportTicketParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter createSupportTicketParameters is required and cannot be null."));
        } else {
            createSupportTicketParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            supportTicketName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            createSupportTicketParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (supportTicketName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter supportTicketName 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 (createSupportTicketParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter createSupportTicketParameters is required and cannot be null."));
        } else {
            createSupportTicketParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                supportTicketName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                createSupportTicketParameters,
                accept,
                context);
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<SupportTicketDetailsInner>, SupportTicketDetailsInner> beginCreateAsync(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(supportTicketName, createSupportTicketParameters);
        return this
            .client
            .<SupportTicketDetailsInner, SupportTicketDetailsInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                SupportTicketDetailsInner.class,
                SupportTicketDetailsInner.class,
                this.client.getContext());
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<SupportTicketDetailsInner>, SupportTicketDetailsInner> beginCreateAsync(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(supportTicketName, createSupportTicketParameters, context);
        return this
            .client
            .<SupportTicketDetailsInner, SupportTicketDetailsInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                SupportTicketDetailsInner.class,
                SupportTicketDetailsInner.class,
                context);
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<SupportTicketDetailsInner>, SupportTicketDetailsInner> beginCreate(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters) {
        return this.beginCreateAsync(supportTicketName, createSupportTicketParameters).getSyncPoller();
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<SupportTicketDetailsInner>, SupportTicketDetailsInner> beginCreate(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters, Context context) {
        return this.beginCreateAsync(supportTicketName, createSupportTicketParameters, context).getSyncPoller();
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SupportTicketDetailsInner> createAsync(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters) {
        return beginCreateAsync(supportTicketName, createSupportTicketParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SupportTicketDetailsInner> createAsync(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters, Context context) {
        return beginCreateAsync(supportTicketName, createSupportTicketParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SupportTicketDetailsInner create(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters) {
        return createAsync(supportTicketName, createSupportTicketParameters).block();
    }

    /**
     * Creates a new support ticket for Subscription and Service limits (Quota), Technical, Billing, and Subscription
     * Management issues for the specified subscription. Learn the [prerequisites](https://aka.ms/supportAPI) required
     * to create a support ticket.&lt;br/&gt;&lt;br/&gt;Always call the Services and ProblemClassifications API to get
     * the most recent set of services and problem categories required for support ticket
     * creation.&lt;br/&gt;&lt;br/&gt;Adding attachments is not currently supported via the API. To add a file to an
     * existing support ticket, visit the [Manage support
     * ticket](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/managesupportrequest) page in
     * the Azure portal, select the support ticket, and use the file upload control to add a new
     * file.&lt;br/&gt;&lt;br/&gt;Providing consent to share diagnostic information with Azure support is currently not
     * supported via the API. The Azure support engineer working on your ticket will reach out to you for consent if
     * your issue requires gathering diagnostic information from your Azure resources.&lt;br/&gt;&lt;br/&gt;**Creating a
     * support ticket for on-behalf-of**: Include _x-ms-authorization-auxiliary_ header to provide an auxiliary token as
     * per
     * [documentation](https://docs.microsoft.com/azure/azure-resource-manager/management/authenticate-multi-tenant).
     * The primary token will be from the tenant for whom a support ticket is being raised against the subscription,
     * i.e. Cloud solution provider (CSP) customer tenant. The auxiliary token will be from the Cloud solution provider
     * (CSP) partner tenant.
     *
     * @param supportTicketName Support ticket name.
     * @param createSupportTicketParameters Support ticket request payload.
     * @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 object that represents SupportTicketDetails resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SupportTicketDetailsInner create(
        String supportTicketName, SupportTicketDetailsInner createSupportTicketParameters, Context context) {
        return createAsync(supportTicketName, createSupportTicketParameters, context).block();
    }

    /**
     * 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 object that represents a collection of SupportTicket resources along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SupportTicketDetailsInner>> 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<SupportTicketDetailsInner>>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 object that represents a collection of SupportTicket resources along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SupportTicketDetailsInner>> 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));
    }
}
