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

package com.azure.digitaltwins.core.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.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.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.models.JsonPatchDocument;
import com.azure.core.util.Context;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsAddOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsAddRelationshipOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsAddRelationshipResponse;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsAddResponse;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsDeleteOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsDeleteRelationshipOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsGetByIdOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsGetByIdResponse;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsGetComponentOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsGetComponentResponse;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsGetRelationshipByIdOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsGetRelationshipByIdResponse;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsListIncomingRelationshipsOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsListRelationshipsOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsSendComponentTelemetryOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsSendTelemetryOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsUpdateComponentOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsUpdateComponentResponse;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsUpdateOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsUpdateRelationshipOptions;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsUpdateRelationshipResponse;
import com.azure.digitaltwins.core.implementation.models.DigitalTwinsUpdateResponse;
import com.azure.digitaltwins.core.implementation.models.ErrorResponseException;
import com.azure.digitaltwins.core.implementation.models.IncomingRelationship;
import com.azure.digitaltwins.core.implementation.models.IncomingRelationshipCollection;
import com.azure.digitaltwins.core.implementation.models.RelationshipCollection;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for AzureDigitalTwinsAPIDigitalTwins to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureDigitalTwinsAPI")
    public interface DigitalTwinsService {
        @Get("/digitaltwins/{id}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsGetByIdResponse> getById(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @QueryParam("api-version") String apiVersion,
                Context context);

        @Put("/digitaltwins/{id}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsAddResponse> add(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @HeaderParam("If-None-Match") String ifNoneMatch,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json") Object twin,
                Context context);

        @Delete("/digitaltwins/{id}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<Void>> delete(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @HeaderParam("If-Match") String ifMatch,
                @QueryParam("api-version") String apiVersion,
                Context context);

        @Patch("/digitaltwins/{id}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsUpdateResponse> update(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @HeaderParam("If-Match") String ifMatch,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json-patch+json") JsonPatchDocument patchDocument,
                Context context);

        @Get("/digitaltwins/{id}/relationships/{relationshipId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsGetRelationshipByIdResponse> getRelationshipById(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @PathParam("relationshipId") String relationshipId,
                @QueryParam("api-version") String apiVersion,
                Context context);

        @Put("/digitaltwins/{id}/relationships/{relationshipId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsAddRelationshipResponse> addRelationship(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @PathParam("relationshipId") String relationshipId,
                @HeaderParam("If-None-Match") String ifNoneMatch,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json") Object relationship,
                Context context);

        @Delete("/digitaltwins/{id}/relationships/{relationshipId}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<Void>> deleteRelationship(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @PathParam("relationshipId") String relationshipId,
                @HeaderParam("If-Match") String ifMatch,
                @QueryParam("api-version") String apiVersion,
                Context context);

        @Patch("/digitaltwins/{id}/relationships/{relationshipId}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsUpdateRelationshipResponse> updateRelationship(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @PathParam("relationshipId") String relationshipId,
                @HeaderParam("If-Match") String ifMatch,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json-patch+json") JsonPatchDocument patchDocument,
                Context context);

        @Get("/digitaltwins/{id}/relationships")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<RelationshipCollection>> listRelationships(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @QueryParam("relationshipName") String relationshipName,
                @QueryParam("api-version") String apiVersion,
                Context context);

        @Get("/digitaltwins/{id}/incomingrelationships")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<IncomingRelationshipCollection>> listIncomingRelationships(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @QueryParam("api-version") String apiVersion,
                Context context);

        @Post("/digitaltwins/{id}/telemetry")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<Void>> sendTelemetry(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @HeaderParam("Message-Id") String messageId,
                @HeaderParam("Telemetry-Source-Time") String telemetrySourceTime,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json") Object telemetry,
                Context context);

        @Post("/digitaltwins/{id}/components/{componentPath}/telemetry")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<Void>> sendComponentTelemetry(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @PathParam("componentPath") String componentPath,
                @HeaderParam("Message-Id") String messageId,
                @HeaderParam("Telemetry-Source-Time") String telemetrySourceTime,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json") Object telemetry,
                Context context);

        @Get("/digitaltwins/{id}/components/{componentPath}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsGetComponentResponse> getComponent(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @PathParam("componentPath") String componentPath,
                @QueryParam("api-version") String apiVersion,
                Context context);

        @Patch("/digitaltwins/{id}/components/{componentPath}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<DigitalTwinsUpdateComponentResponse> updateComponent(
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                @PathParam("id") String id,
                @PathParam("componentPath") String componentPath,
                @HeaderParam("If-Match") String ifMatch,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json-patch+json") JsonPatchDocument patchDocument,
                Context context);

        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<RelationshipCollection>> listRelationshipsNext(
                @PathParam(value = "nextLink", encoded = true) String nextLink,
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                Context context);

        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<IncomingRelationshipCollection>> listIncomingRelationshipsNext(
                @PathParam(value = "nextLink", encoded = true) String nextLink,
                @HostParam("$host") String host,
                @HeaderParam("traceparent") String traceparent,
                @HeaderParam("tracestate") String tracestate,
                Context context);
    }

    /**
     * Retrieves a digital twin. Status codes: * 200 OK * 400 Bad Request * InvalidArgument - The digital twin id is
     * invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was not found.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param digitalTwinsGetByIdOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return any object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<DigitalTwinsGetByIdResponse> getByIdWithResponseAsync(
            String id, DigitalTwinsGetByIdOptions digitalTwinsGetByIdOptions, Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (digitalTwinsGetByIdOptions != null) {
            digitalTwinsGetByIdOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsGetByIdOptions != null) {
            traceparentInternal = digitalTwinsGetByIdOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsGetByIdOptions != null) {
            tracestateInternal = digitalTwinsGetByIdOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.getById(
                this.client.getHost(), traceparent, tracestate, id, this.client.getApiVersion(), context);
    }

    /**
     * Adds or replaces a digital twin. Status codes: * 200 OK * 400 Bad Request * InvalidArgument - The digital twin id
     * or payload is invalid. * ModelDecommissioned - The model for the digital twin is decommissioned. *
     * TwinLimitReached - The maximum number of digital twins allowed has been reached. * ValidationFailed - The digital
     * twin payload is not valid. * 412 Precondition Failed * PreconditionFailed - The precondition check (If-Match or
     * If-None-Match) failed.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param twin Any object.
     * @param digitalTwinsAddOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return any object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<DigitalTwinsAddResponse> addWithResponseAsync(
            String id, Object twin, DigitalTwinsAddOptions digitalTwinsAddOptions, Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (twin == null) {
            return Mono.error(new IllegalArgumentException("Parameter twin is required and cannot be null."));
        }
        if (digitalTwinsAddOptions != null) {
            digitalTwinsAddOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsAddOptions != null) {
            traceparentInternal = digitalTwinsAddOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsAddOptions != null) {
            tracestateInternal = digitalTwinsAddOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        String ifNoneMatchInternal = null;
        if (digitalTwinsAddOptions != null) {
            ifNoneMatchInternal = digitalTwinsAddOptions.getIfNoneMatch();
        }
        String ifNoneMatch = ifNoneMatchInternal;
        return service.add(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                ifNoneMatch,
                this.client.getApiVersion(),
                twin,
                context);
    }

    /**
     * Deletes a digital twin. All relationships referencing the digital twin must already be deleted. Status codes: *
     * 204 No Content * 400 Bad Request * InvalidArgument - The digital twin id is invalid. * RelationshipsNotDeleted -
     * The digital twin contains relationships. * 404 Not Found * DigitalTwinNotFound - The digital twin was not found.
     * * 412 Precondition Failed * PreconditionFailed - The precondition check (If-Match or If-None-Match) failed.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param digitalTwinsDeleteOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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>> deleteWithResponseAsync(
            String id, DigitalTwinsDeleteOptions digitalTwinsDeleteOptions, Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (digitalTwinsDeleteOptions != null) {
            digitalTwinsDeleteOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsDeleteOptions != null) {
            traceparentInternal = digitalTwinsDeleteOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsDeleteOptions != null) {
            tracestateInternal = digitalTwinsDeleteOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        String ifMatchInternal = null;
        if (digitalTwinsDeleteOptions != null) {
            ifMatchInternal = digitalTwinsDeleteOptions.getIfMatch();
        }
        String ifMatch = ifMatchInternal;
        return service.delete(
                this.client.getHost(), traceparent, tracestate, id, ifMatch, this.client.getApiVersion(), context);
    }

    /**
     * Updates a digital twin. Status codes: * 204 No Content * 400 Bad Request * InvalidArgument - The digital twin id
     * or payload is invalid. * JsonPatchInvalid - The JSON Patch provided is invalid. * ValidationFailed - Applying the
     * patch results in an invalid digital twin. * 404 Not Found * DigitalTwinNotFound - The digital twin was not found.
     * * 412 Precondition Failed * PreconditionFailed - The precondition check (If-Match or If-None-Match) failed.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param patchDocument Array of any.
     * @param digitalTwinsUpdateOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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<DigitalTwinsUpdateResponse> updateWithResponseAsync(
            String id,
            JsonPatchDocument patchDocument,
            DigitalTwinsUpdateOptions digitalTwinsUpdateOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (patchDocument == null) {
            return Mono.error(new IllegalArgumentException("Parameter patchDocument is required and cannot be null."));
        }
        if (digitalTwinsUpdateOptions != null) {
            digitalTwinsUpdateOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsUpdateOptions != null) {
            traceparentInternal = digitalTwinsUpdateOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsUpdateOptions != null) {
            tracestateInternal = digitalTwinsUpdateOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        String ifMatchInternal = null;
        if (digitalTwinsUpdateOptions != null) {
            ifMatchInternal = digitalTwinsUpdateOptions.getIfMatch();
        }
        String ifMatch = ifMatchInternal;
        return service.update(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                ifMatch,
                this.client.getApiVersion(),
                patchDocument,
                context);
    }

    /**
     * Retrieves a relationship between two digital twins. Status codes: * 200 OK * 400 Bad Request * InvalidArgument -
     * The digital twin id or relationship id is invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was
     * not found. * RelationshipNotFound - The relationship was not found.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param relationshipId The id of the relationship. The id is unique within the digital twin and case sensitive.
     * @param digitalTwinsGetRelationshipByIdOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return any object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<DigitalTwinsGetRelationshipByIdResponse> getRelationshipByIdWithResponseAsync(
            String id,
            String relationshipId,
            DigitalTwinsGetRelationshipByIdOptions digitalTwinsGetRelationshipByIdOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (relationshipId == null) {
            return Mono.error(new IllegalArgumentException("Parameter relationshipId is required and cannot be null."));
        }
        if (digitalTwinsGetRelationshipByIdOptions != null) {
            digitalTwinsGetRelationshipByIdOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsGetRelationshipByIdOptions != null) {
            traceparentInternal = digitalTwinsGetRelationshipByIdOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsGetRelationshipByIdOptions != null) {
            tracestateInternal = digitalTwinsGetRelationshipByIdOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.getRelationshipById(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                relationshipId,
                this.client.getApiVersion(),
                context);
    }

    /**
     * Adds a relationship between two digital twins. Status codes: * 200 OK * 400 Bad Request * InvalidArgument - The
     * digital twin id, relationship id, or payload is invalid. * InvalidRelationship - The relationship is invalid. *
     * OperationNotAllowed - The relationship cannot connect to the same digital twin. * ValidationFailed - The
     * relationship content is invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was not found. *
     * TargetTwinNotFound - The digital twin target of the relationship was not found. * 412 Precondition Failed *
     * PreconditionFailed - The precondition check (If-Match or If-None-Match) failed.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param relationshipId The id of the relationship. The id is unique within the digital twin and case sensitive.
     * @param relationship Any object.
     * @param digitalTwinsAddRelationshipOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return any object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<DigitalTwinsAddRelationshipResponse> addRelationshipWithResponseAsync(
            String id,
            String relationshipId,
            Object relationship,
            DigitalTwinsAddRelationshipOptions digitalTwinsAddRelationshipOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (relationshipId == null) {
            return Mono.error(new IllegalArgumentException("Parameter relationshipId is required and cannot be null."));
        }
        if (relationship == null) {
            return Mono.error(new IllegalArgumentException("Parameter relationship is required and cannot be null."));
        }
        if (digitalTwinsAddRelationshipOptions != null) {
            digitalTwinsAddRelationshipOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsAddRelationshipOptions != null) {
            traceparentInternal = digitalTwinsAddRelationshipOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsAddRelationshipOptions != null) {
            tracestateInternal = digitalTwinsAddRelationshipOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        String ifNoneMatchInternal = null;
        if (digitalTwinsAddRelationshipOptions != null) {
            ifNoneMatchInternal = digitalTwinsAddRelationshipOptions.getIfNoneMatch();
        }
        String ifNoneMatch = ifNoneMatchInternal;
        return service.addRelationship(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                relationshipId,
                ifNoneMatch,
                this.client.getApiVersion(),
                relationship,
                context);
    }

    /**
     * Deletes a relationship between two digital twins. Status codes: * 204 No Content * 400 Bad Request *
     * InvalidArgument - The digital twin id or relationship id is invalid. * 404 Not Found * DigitalTwinNotFound - The
     * digital twin was not found. * RelationshipNotFound - The relationship was not found. * 412 Precondition Failed *
     * PreconditionFailed - The precondition check (If-Match or If-None-Match) failed.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param relationshipId The id of the relationship. The id is unique within the digital twin and case sensitive.
     * @param digitalTwinsDeleteRelationshipOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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>> deleteRelationshipWithResponseAsync(
            String id,
            String relationshipId,
            DigitalTwinsDeleteRelationshipOptions digitalTwinsDeleteRelationshipOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (relationshipId == null) {
            return Mono.error(new IllegalArgumentException("Parameter relationshipId is required and cannot be null."));
        }
        if (digitalTwinsDeleteRelationshipOptions != null) {
            digitalTwinsDeleteRelationshipOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsDeleteRelationshipOptions != null) {
            traceparentInternal = digitalTwinsDeleteRelationshipOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsDeleteRelationshipOptions != null) {
            tracestateInternal = digitalTwinsDeleteRelationshipOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        String ifMatchInternal = null;
        if (digitalTwinsDeleteRelationshipOptions != null) {
            ifMatchInternal = digitalTwinsDeleteRelationshipOptions.getIfMatch();
        }
        String ifMatch = ifMatchInternal;
        return service.deleteRelationship(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                relationshipId,
                ifMatch,
                this.client.getApiVersion(),
                context);
    }

    /**
     * Updates the properties on a relationship between two digital twins. Status codes: * 204 No Content * 400 Bad
     * Request * InvalidArgument - The digital twin id or relationship id is invalid. * InvalidRelationship - The
     * relationship is invalid. * JsonPatchInvalid - The JSON Patch provided is invalid. * ValidationFailed - The
     * relationship content is invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was not found. *
     * RelationshipNotFound - The relationship was not found. * 409 Conflict * RelationshipAlreadyExists - The
     * relationship already exists. * 412 Precondition Failed * PreconditionFailed - The precondition check (If-Match or
     * If-None-Match) failed.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param relationshipId The id of the relationship. The id is unique within the digital twin and case sensitive.
     * @param patchDocument Array of any.
     * @param digitalTwinsUpdateRelationshipOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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<DigitalTwinsUpdateRelationshipResponse> updateRelationshipWithResponseAsync(
            String id,
            String relationshipId,
            JsonPatchDocument patchDocument,
            DigitalTwinsUpdateRelationshipOptions digitalTwinsUpdateRelationshipOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (relationshipId == null) {
            return Mono.error(new IllegalArgumentException("Parameter relationshipId is required and cannot be null."));
        }
        if (patchDocument == null) {
            return Mono.error(new IllegalArgumentException("Parameter patchDocument is required and cannot be null."));
        }
        if (digitalTwinsUpdateRelationshipOptions != null) {
            digitalTwinsUpdateRelationshipOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsUpdateRelationshipOptions != null) {
            traceparentInternal = digitalTwinsUpdateRelationshipOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsUpdateRelationshipOptions != null) {
            tracestateInternal = digitalTwinsUpdateRelationshipOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        String ifMatchInternal = null;
        if (digitalTwinsUpdateRelationshipOptions != null) {
            ifMatchInternal = digitalTwinsUpdateRelationshipOptions.getIfMatch();
        }
        String ifMatch = ifMatchInternal;
        return service.updateRelationship(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                relationshipId,
                ifMatch,
                this.client.getApiVersion(),
                patchDocument,
                context);
    }

    /**
     * Retrieves the relationships from a digital twin. Status codes: * 200 OK * 400 Bad Request * InvalidArgument - The
     * digital twin id is invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was not found.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param relationshipName The name of the relationship.
     * @param digitalTwinsListRelationshipsOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a collection of relationships which relate digital twins together.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<Object>> listRelationshipsSinglePageAsync(
            String id,
            String relationshipName,
            DigitalTwinsListRelationshipsOptions digitalTwinsListRelationshipsOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (digitalTwinsListRelationshipsOptions != null) {
            digitalTwinsListRelationshipsOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsListRelationshipsOptions != null) {
            traceparentInternal = digitalTwinsListRelationshipsOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsListRelationshipsOptions != null) {
            tracestateInternal = digitalTwinsListRelationshipsOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.listRelationships(
                        this.client.getHost(),
                        traceparent,
                        tracestate,
                        id,
                        relationshipName,
                        this.client.getApiVersion(),
                        context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Retrieves all incoming relationship for a digital twin. Status codes: * 200 OK * 400 Bad Request *
     * InvalidArgument - The digital twin id is invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was
     * not found.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param digitalTwinsListIncomingRelationshipsOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a collection of incoming relationships which relate digital twins together.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<IncomingRelationship>> listIncomingRelationshipsSinglePageAsync(
            String id,
            DigitalTwinsListIncomingRelationshipsOptions digitalTwinsListIncomingRelationshipsOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (digitalTwinsListIncomingRelationshipsOptions != null) {
            digitalTwinsListIncomingRelationshipsOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsListIncomingRelationshipsOptions != null) {
            traceparentInternal = digitalTwinsListIncomingRelationshipsOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsListIncomingRelationshipsOptions != null) {
            tracestateInternal = digitalTwinsListIncomingRelationshipsOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.listIncomingRelationships(
                        this.client.getHost(), traceparent, tracestate, id, this.client.getApiVersion(), context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Sends telemetry on behalf of a digital twin. Status codes: * 204 No Content * 400 Bad Request * InvalidArgument -
     * The digital twin id or message id is invalid. * ValidationFailed - The telemetry content is invalid. * 404 Not
     * Found * DigitalTwinNotFound - The digital twin was not found.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param messageId A unique message identifier (in the scope of the digital twin id) that is commonly used for
     *     de-duplicating messages.
     * @param telemetry Any object.
     * @param telemetrySourceTime An RFC 3339 timestamp that identifies the time the telemetry was measured.
     * @param digitalTwinsSendTelemetryOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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>> sendTelemetryWithResponseAsync(
            String id,
            String messageId,
            Object telemetry,
            String telemetrySourceTime,
            DigitalTwinsSendTelemetryOptions digitalTwinsSendTelemetryOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (messageId == null) {
            return Mono.error(new IllegalArgumentException("Parameter messageId is required and cannot be null."));
        }
        if (telemetry == null) {
            return Mono.error(new IllegalArgumentException("Parameter telemetry is required and cannot be null."));
        }
        if (digitalTwinsSendTelemetryOptions != null) {
            digitalTwinsSendTelemetryOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsSendTelemetryOptions != null) {
            traceparentInternal = digitalTwinsSendTelemetryOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsSendTelemetryOptions != null) {
            tracestateInternal = digitalTwinsSendTelemetryOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.sendTelemetry(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                messageId,
                telemetrySourceTime,
                this.client.getApiVersion(),
                telemetry,
                context);
    }

    /**
     * Sends telemetry on behalf of a component in a digital twin. Status codes: * 204 No Content * 400 Bad Request *
     * InvalidArgument - The digital twin id, message id, or component path is invalid. * ValidationFailed - The
     * telemetry content is invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was not found. *
     * ComponentNotFound - The component path was not found.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param componentPath The name of the DTDL component.
     * @param messageId A unique message identifier (in the scope of the digital twin id) that is commonly used for
     *     de-duplicating messages.
     * @param telemetry Any object.
     * @param telemetrySourceTime An RFC 3339 timestamp that identifies the time the telemetry was measured.
     * @param digitalTwinsSendComponentTelemetryOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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>> sendComponentTelemetryWithResponseAsync(
            String id,
            String componentPath,
            String messageId,
            Object telemetry,
            String telemetrySourceTime,
            DigitalTwinsSendComponentTelemetryOptions digitalTwinsSendComponentTelemetryOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (componentPath == null) {
            return Mono.error(new IllegalArgumentException("Parameter componentPath is required and cannot be null."));
        }
        if (messageId == null) {
            return Mono.error(new IllegalArgumentException("Parameter messageId is required and cannot be null."));
        }
        if (telemetry == null) {
            return Mono.error(new IllegalArgumentException("Parameter telemetry is required and cannot be null."));
        }
        if (digitalTwinsSendComponentTelemetryOptions != null) {
            digitalTwinsSendComponentTelemetryOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsSendComponentTelemetryOptions != null) {
            traceparentInternal = digitalTwinsSendComponentTelemetryOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsSendComponentTelemetryOptions != null) {
            tracestateInternal = digitalTwinsSendComponentTelemetryOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.sendComponentTelemetry(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                componentPath,
                messageId,
                telemetrySourceTime,
                this.client.getApiVersion(),
                telemetry,
                context);
    }

    /**
     * Retrieves a component from a digital twin. Status codes: * 200 OK * 400 Bad Request * InvalidArgument - The
     * digital twin id or component path is invalid. * 404 Not Found * DigitalTwinNotFound - The digital twin was not
     * found. * ComponentNotFound - The component path was not found.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param componentPath The name of the DTDL component.
     * @param digitalTwinsGetComponentOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return any object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<DigitalTwinsGetComponentResponse> getComponentWithResponseAsync(
            String id,
            String componentPath,
            DigitalTwinsGetComponentOptions digitalTwinsGetComponentOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (componentPath == null) {
            return Mono.error(new IllegalArgumentException("Parameter componentPath is required and cannot be null."));
        }
        if (digitalTwinsGetComponentOptions != null) {
            digitalTwinsGetComponentOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsGetComponentOptions != null) {
            traceparentInternal = digitalTwinsGetComponentOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsGetComponentOptions != null) {
            tracestateInternal = digitalTwinsGetComponentOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.getComponent(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                componentPath,
                this.client.getApiVersion(),
                context);
    }

    /**
     * Updates a component on a digital twin. Status codes: * 204 No Content * 400 Bad Request * InvalidArgument - The
     * digital twin id, component path, or payload is invalid. * JsonPatchInvalid - The JSON Patch provided is invalid.
     * * ValidationFailed - Applying the patch results in an invalid digital twin. * 404 Not Found * DigitalTwinNotFound
     * - The digital twin was not found. * 412 Precondition Failed * PreconditionFailed - The precondition check
     * (If-Match or If-None-Match) failed.
     *
     * @param id The id of the digital twin. The id is unique within the service and case sensitive.
     * @param componentPath The name of the DTDL component.
     * @param patchDocument Array of any.
     * @param digitalTwinsUpdateComponentOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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<DigitalTwinsUpdateComponentResponse> updateComponentWithResponseAsync(
            String id,
            String componentPath,
            JsonPatchDocument patchDocument,
            DigitalTwinsUpdateComponentOptions digitalTwinsUpdateComponentOptions,
            Context context) {
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (id == null) {
            return Mono.error(new IllegalArgumentException("Parameter id is required and cannot be null."));
        }
        if (componentPath == null) {
            return Mono.error(new IllegalArgumentException("Parameter componentPath is required and cannot be null."));
        }
        if (patchDocument == null) {
            return Mono.error(new IllegalArgumentException("Parameter patchDocument is required and cannot be null."));
        }
        if (digitalTwinsUpdateComponentOptions != null) {
            digitalTwinsUpdateComponentOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsUpdateComponentOptions != null) {
            traceparentInternal = digitalTwinsUpdateComponentOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsUpdateComponentOptions != null) {
            tracestateInternal = digitalTwinsUpdateComponentOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        String ifMatchInternal = null;
        if (digitalTwinsUpdateComponentOptions != null) {
            ifMatchInternal = digitalTwinsUpdateComponentOptions.getIfMatch();
        }
        String ifMatch = ifMatchInternal;
        return service.updateComponent(
                this.client.getHost(),
                traceparent,
                tracestate,
                id,
                componentPath,
                ifMatch,
                this.client.getApiVersion(),
                patchDocument,
                context);
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @param digitalTwinsListRelationshipsOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a collection of relationships which relate digital twins together.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<Object>> listRelationshipsNextSinglePageAsync(
            String nextLink,
            DigitalTwinsListRelationshipsOptions digitalTwinsListRelationshipsOptions,
            Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (digitalTwinsListRelationshipsOptions != null) {
            digitalTwinsListRelationshipsOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsListRelationshipsOptions != null) {
            traceparentInternal = digitalTwinsListRelationshipsOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsListRelationshipsOptions != null) {
            tracestateInternal = digitalTwinsListRelationshipsOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.listRelationshipsNext(nextLink, this.client.getHost(), traceparent, tracestate, context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @param digitalTwinsListIncomingRelationshipsOptions Parameter group.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a collection of incoming relationships which relate digital twins together.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<IncomingRelationship>> listIncomingRelationshipsNextSinglePageAsync(
            String nextLink,
            DigitalTwinsListIncomingRelationshipsOptions digitalTwinsListIncomingRelationshipsOptions,
            Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getHost() == null) {
            return Mono.error(
                    new IllegalArgumentException("Parameter this.client.getHost() is required and cannot be null."));
        }
        if (digitalTwinsListIncomingRelationshipsOptions != null) {
            digitalTwinsListIncomingRelationshipsOptions.validate();
        }
        String traceparentInternal = null;
        if (digitalTwinsListIncomingRelationshipsOptions != null) {
            traceparentInternal = digitalTwinsListIncomingRelationshipsOptions.getTraceparent();
        }
        String traceparent = traceparentInternal;
        String tracestateInternal = null;
        if (digitalTwinsListIncomingRelationshipsOptions != null) {
            tracestateInternal = digitalTwinsListIncomingRelationshipsOptions.getTracestate();
        }
        String tracestate = tracestateInternal;
        return service.listIncomingRelationshipsNext(nextLink, this.client.getHost(), traceparent, tracestate, context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }
}
