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

package com.azure.communication.callautomation.implementation;

import com.azure.communication.callautomation.implementation.models.AnswerCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.CallConnectionPropertiesInternal;
import com.azure.communication.callautomation.implementation.models.CommunicationErrorResponseException;
import com.azure.communication.callautomation.implementation.models.CreateCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.RedirectCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.RejectCallRequestInternal;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Post;
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.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.util.Context;
import com.azure.core.util.DateTimeRfc1123;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
import java.time.OffsetDateTime;
import java.util.UUID;
import reactor.core.publisher.Mono;

/** Initializes a new instance of the AzureCommunicationCallAutomationService type. */
public final class AzureCommunicationCallAutomationServiceImpl {
    /** The proxy service used to perform REST calls. */
    private final AzureCommunicationCallAutomationServiceService service;

    /** The endpoint of the Azure Communication resource. */
    private final String endpoint;

    /**
     * Gets The endpoint of the Azure Communication resource.
     *
     * @return the endpoint value.
     */
    public String getEndpoint() {
        return this.endpoint;
    }

    /** Api Version. */
    private final String apiVersion;

    /**
     * Gets Api Version.
     *
     * @return the apiVersion value.
     */
    public String getApiVersion() {
        return this.apiVersion;
    }

    /** The HTTP pipeline to send requests through. */
    private final HttpPipeline httpPipeline;

    /**
     * Gets The HTTP pipeline to send requests through.
     *
     * @return the httpPipeline value.
     */
    public HttpPipeline getHttpPipeline() {
        return this.httpPipeline;
    }

    /** The serializer to serialize an object into a string. */
    private final SerializerAdapter serializerAdapter;

    /**
     * Gets The serializer to serialize an object into a string.
     *
     * @return the serializerAdapter value.
     */
    public SerializerAdapter getSerializerAdapter() {
        return this.serializerAdapter;
    }

    /** The CallConnectionsImpl object to access its operations. */
    private final CallConnectionsImpl callConnections;

    /**
     * Gets the CallConnectionsImpl object to access its operations.
     *
     * @return the CallConnectionsImpl object.
     */
    public CallConnectionsImpl getCallConnections() {
        return this.callConnections;
    }

    /** The CallMediasImpl object to access its operations. */
    private final CallMediasImpl callMedias;

    /**
     * Gets the CallMediasImpl object to access its operations.
     *
     * @return the CallMediasImpl object.
     */
    public CallMediasImpl getCallMedias() {
        return this.callMedias;
    }

    /** The CallDialogsImpl object to access its operations. */
    private final CallDialogsImpl callDialogs;

    /**
     * Gets the CallDialogsImpl object to access its operations.
     *
     * @return the CallDialogsImpl object.
     */
    public CallDialogsImpl getCallDialogs() {
        return this.callDialogs;
    }

    /** The CallRecordingsImpl object to access its operations. */
    private final CallRecordingsImpl callRecordings;

    /**
     * Gets the CallRecordingsImpl object to access its operations.
     *
     * @return the CallRecordingsImpl object.
     */
    public CallRecordingsImpl getCallRecordings() {
        return this.callRecordings;
    }

    /**
     * Initializes an instance of AzureCommunicationCallAutomationService client.
     *
     * @param endpoint The endpoint of the Azure Communication resource.
     * @param apiVersion Api Version.
     */
    AzureCommunicationCallAutomationServiceImpl(String endpoint, String apiVersion) {
        this(
                new HttpPipelineBuilder()
                        .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
                        .build(),
                JacksonAdapter.createDefaultSerializerAdapter(),
                endpoint,
                apiVersion);
    }

    /**
     * Initializes an instance of AzureCommunicationCallAutomationService client.
     *
     * @param httpPipeline The HTTP pipeline to send requests through.
     * @param endpoint The endpoint of the Azure Communication resource.
     * @param apiVersion Api Version.
     */
    AzureCommunicationCallAutomationServiceImpl(HttpPipeline httpPipeline, String endpoint, String apiVersion) {
        this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion);
    }

    /**
     * Initializes an instance of AzureCommunicationCallAutomationService client.
     *
     * @param httpPipeline The HTTP pipeline to send requests through.
     * @param serializerAdapter The serializer to serialize an object into a string.
     * @param endpoint The endpoint of the Azure Communication resource.
     * @param apiVersion Api Version.
     */
    AzureCommunicationCallAutomationServiceImpl(
            HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, String apiVersion) {
        this.httpPipeline = httpPipeline;
        this.serializerAdapter = serializerAdapter;
        this.endpoint = endpoint;
        this.apiVersion = apiVersion;
        this.callConnections = new CallConnectionsImpl(this);
        this.callMedias = new CallMediasImpl(this);
        this.callDialogs = new CallDialogsImpl(this);
        this.callRecordings = new CallRecordingsImpl(this);
        this.service =
                RestProxy.create(
                        AzureCommunicationCallAutomationServiceService.class,
                        this.httpPipeline,
                        this.getSerializerAdapter());
    }

    /**
     * The interface defining all the services for AzureCommunicationCallAutomationService to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "AzureCommunicationCa")
    public interface AzureCommunicationCallAutomationServiceService {
        @Post("/calling/callConnections")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
        Mono<Response<CallConnectionPropertiesInternal>> createCall(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
                @HeaderParam("Repeatability-First-Sent") DateTimeRfc1123 repeatabilityFirstSent,
                @BodyParam("application/json") CreateCallRequestInternal createCallRequest,
                @HeaderParam("Accept") String accept,
                Context context);

        @Post("/calling/callConnections:answer")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
        Mono<Response<CallConnectionPropertiesInternal>> answerCall(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
                @HeaderParam("Repeatability-First-Sent") DateTimeRfc1123 repeatabilityFirstSent,
                @BodyParam("application/json") AnswerCallRequestInternal answerCallRequest,
                @HeaderParam("Accept") String accept,
                Context context);

        @Post("/calling/callConnections:redirect")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
        Mono<Response<Void>> redirectCall(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
                @HeaderParam("Repeatability-First-Sent") DateTimeRfc1123 repeatabilityFirstSent,
                @BodyParam("application/json") RedirectCallRequestInternal redirectCallRequest,
                @HeaderParam("Accept") String accept,
                Context context);

        @Post("/calling/callConnections:reject")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
        Mono<Response<Void>> rejectCall(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
                @HeaderParam("Repeatability-First-Sent") DateTimeRfc1123 repeatabilityFirstSent,
                @BodyParam("application/json") RejectCallRequestInternal rejectCallRequest,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Create an outbound call.
     *
     * @param createCallRequest The create call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<CallConnectionPropertiesInternal>> createCallWithResponseAsync(
            CreateCallRequestInternal createCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return FluxUtil.withContext(
                context ->
                        service.createCall(
                                this.getEndpoint(),
                                this.getApiVersion(),
                                repeatabilityRequestID,
                                repeatabilityFirstSentConverted,
                                createCallRequest,
                                accept,
                                context));
    }

    /**
     * Create an outbound call.
     *
     * @param createCallRequest The create call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<CallConnectionPropertiesInternal>> createCallWithResponseAsync(
            CreateCallRequestInternal createCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return service.createCall(
                this.getEndpoint(),
                this.getApiVersion(),
                repeatabilityRequestID,
                repeatabilityFirstSentConverted,
                createCallRequest,
                accept,
                context);
    }

    /**
     * Create an outbound call.
     *
     * @param createCallRequest The create call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<CallConnectionPropertiesInternal> createCallAsync(
            CreateCallRequestInternal createCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        return createCallWithResponseAsync(createCallRequest, repeatabilityRequestID, repeatabilityFirstSent)
                .flatMap(
                        (Response<CallConnectionPropertiesInternal> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Create an outbound call.
     *
     * @param createCallRequest The create call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<CallConnectionPropertiesInternal> createCallAsync(
            CreateCallRequestInternal createCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return createCallWithResponseAsync(createCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .flatMap(
                        (Response<CallConnectionPropertiesInternal> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Create an outbound call.
     *
     * @param createCallRequest The create call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CallConnectionPropertiesInternal createCall(
            CreateCallRequestInternal createCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        return createCallAsync(createCallRequest, repeatabilityRequestID, repeatabilityFirstSent).block();
    }

    /**
     * Create an outbound call.
     *
     * @param createCallRequest The create call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CallConnectionPropertiesInternal> createCallWithResponse(
            CreateCallRequestInternal createCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return createCallWithResponseAsync(createCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .block();
    }

    /**
     * Answer a call using the IncomingCallContext from Event Grid.
     *
     * @param answerCallRequest The answer call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<CallConnectionPropertiesInternal>> answerCallWithResponseAsync(
            AnswerCallRequestInternal answerCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return FluxUtil.withContext(
                context ->
                        service.answerCall(
                                this.getEndpoint(),
                                this.getApiVersion(),
                                repeatabilityRequestID,
                                repeatabilityFirstSentConverted,
                                answerCallRequest,
                                accept,
                                context));
    }

    /**
     * Answer a call using the IncomingCallContext from Event Grid.
     *
     * @param answerCallRequest The answer call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<CallConnectionPropertiesInternal>> answerCallWithResponseAsync(
            AnswerCallRequestInternal answerCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return service.answerCall(
                this.getEndpoint(),
                this.getApiVersion(),
                repeatabilityRequestID,
                repeatabilityFirstSentConverted,
                answerCallRequest,
                accept,
                context);
    }

    /**
     * Answer a call using the IncomingCallContext from Event Grid.
     *
     * @param answerCallRequest The answer call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<CallConnectionPropertiesInternal> answerCallAsync(
            AnswerCallRequestInternal answerCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        return answerCallWithResponseAsync(answerCallRequest, repeatabilityRequestID, repeatabilityFirstSent)
                .flatMap(
                        (Response<CallConnectionPropertiesInternal> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Answer a call using the IncomingCallContext from Event Grid.
     *
     * @param answerCallRequest The answer call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<CallConnectionPropertiesInternal> answerCallAsync(
            AnswerCallRequestInternal answerCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return answerCallWithResponseAsync(answerCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .flatMap(
                        (Response<CallConnectionPropertiesInternal> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Answer a call using the IncomingCallContext from Event Grid.
     *
     * @param answerCallRequest The answer call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CallConnectionPropertiesInternal answerCall(
            AnswerCallRequestInternal answerCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        return answerCallAsync(answerCallRequest, repeatabilityRequestID, repeatabilityFirstSent).block();
    }

    /**
     * Answer a call using the IncomingCallContext from Event Grid.
     *
     * @param answerCallRequest The answer call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of a call connection.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CallConnectionPropertiesInternal> answerCallWithResponse(
            AnswerCallRequestInternal answerCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return answerCallWithResponseAsync(answerCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .block();
    }

    /**
     * Redirect a call.
     *
     * @param redirectCallRequest The redirect call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> redirectCallWithResponseAsync(
            RedirectCallRequestInternal redirectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return FluxUtil.withContext(
                context ->
                        service.redirectCall(
                                this.getEndpoint(),
                                this.getApiVersion(),
                                repeatabilityRequestID,
                                repeatabilityFirstSentConverted,
                                redirectCallRequest,
                                accept,
                                context));
    }

    /**
     * Redirect a call.
     *
     * @param redirectCallRequest The redirect call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> redirectCallWithResponseAsync(
            RedirectCallRequestInternal redirectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return service.redirectCall(
                this.getEndpoint(),
                this.getApiVersion(),
                repeatabilityRequestID,
                repeatabilityFirstSentConverted,
                redirectCallRequest,
                accept,
                context);
    }

    /**
     * Redirect a call.
     *
     * @param redirectCallRequest The redirect call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> redirectCallAsync(
            RedirectCallRequestInternal redirectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        return redirectCallWithResponseAsync(redirectCallRequest, repeatabilityRequestID, repeatabilityFirstSent)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Redirect a call.
     *
     * @param redirectCallRequest The redirect call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> redirectCallAsync(
            RedirectCallRequestInternal redirectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return redirectCallWithResponseAsync(
                        redirectCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Redirect a call.
     *
     * @param redirectCallRequest The redirect call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException 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 redirectCall(
            RedirectCallRequestInternal redirectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        redirectCallAsync(redirectCallRequest, repeatabilityRequestID, repeatabilityFirstSent).block();
    }

    /**
     * Redirect a call.
     *
     * @param redirectCallRequest The redirect call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> redirectCallWithResponse(
            RedirectCallRequestInternal redirectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return redirectCallWithResponseAsync(
                        redirectCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .block();
    }

    /**
     * Reject the call.
     *
     * @param rejectCallRequest The reject call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> rejectCallWithResponseAsync(
            RejectCallRequestInternal rejectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return FluxUtil.withContext(
                context ->
                        service.rejectCall(
                                this.getEndpoint(),
                                this.getApiVersion(),
                                repeatabilityRequestID,
                                repeatabilityFirstSentConverted,
                                rejectCallRequest,
                                accept,
                                context));
    }

    /**
     * Reject the call.
     *
     * @param rejectCallRequest The reject call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> rejectCallWithResponseAsync(
            RejectCallRequestInternal rejectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        final String accept = "application/json";
        DateTimeRfc1123 repeatabilityFirstSentConverted =
                repeatabilityFirstSent == null ? null : new DateTimeRfc1123(repeatabilityFirstSent);
        return service.rejectCall(
                this.getEndpoint(),
                this.getApiVersion(),
                repeatabilityRequestID,
                repeatabilityFirstSentConverted,
                rejectCallRequest,
                accept,
                context);
    }

    /**
     * Reject the call.
     *
     * @param rejectCallRequest The reject call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> rejectCallAsync(
            RejectCallRequestInternal rejectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        return rejectCallWithResponseAsync(rejectCallRequest, repeatabilityRequestID, repeatabilityFirstSent)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Reject the call.
     *
     * @param rejectCallRequest The reject call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> rejectCallAsync(
            RejectCallRequestInternal rejectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return rejectCallWithResponseAsync(rejectCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Reject the call.
     *
     * @param rejectCallRequest The reject call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException 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 rejectCall(
            RejectCallRequestInternal rejectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent) {
        rejectCallAsync(rejectCallRequest, repeatabilityRequestID, repeatabilityFirstSent).block();
    }

    /**
     * Reject the call.
     *
     * @param rejectCallRequest The reject call request.
     * @param repeatabilityRequestID If specified, the client directs that the request is repeatable; that is, that the
     *     client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate
     *     response without the server executing the request multiple times. The value of the Repeatability-Request-Id
     *     is an opaque string representing a client-generated unique identifier for the request. It is a version 4
     *     (random) UUID.
     * @param repeatabilityFirstSent If Repeatability-Request-ID header is specified, then Repeatability-First-Sent
     *     header must also be specified. The value should be the date and time at which the request was first created,
     *     expressed using the IMF-fixdate form of HTTP-date. Example: Sun, 06 Nov 1994 08:49:37 GMT.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CommunicationErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> rejectCallWithResponse(
            RejectCallRequestInternal rejectCallRequest,
            UUID repeatabilityRequestID,
            OffsetDateTime repeatabilityFirstSent,
            Context context) {
        return rejectCallWithResponseAsync(rejectCallRequest, repeatabilityRequestID, repeatabilityFirstSent, context)
                .block();
    }
}
