internal Response Update(
            string id,
            string patchDocument,
            UpdateDigitalTwinOptions digitalTwinsUpdateOptions = null,
            CancellationToken cancellationToken = default)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (patchDocument == null)
            {
                throw new ArgumentNullException(nameof(patchDocument));
            }

            using HttpMessage message = CreateUpdateRequest(id, patchDocument, digitalTwinsUpdateOptions);
            _pipeline.Send(message, cancellationToken);
            switch (message.Response.Status)
            {
            case 202:
            case 204:
                return(message.Response);

            default:
                throw _clientDiagnostics.CreateRequestFailedException(message.Response);
            }
        }
        internal async Task <Response> UpdateAsync(
            string id,
            string patchDocument,
            UpdateDigitalTwinOptions digitalTwinsUpdateOptions = null,
            CancellationToken cancellationToken = default)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (patchDocument == null)
            {
                throw new ArgumentNullException(nameof(patchDocument));
            }

            using HttpMessage message = CreateUpdateRequest(id, patchDocument, digitalTwinsUpdateOptions);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 202:
            case 204:
                return(message.Response);

            default:
                throw await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }
        internal HttpMessage CreateUpdateRequest(string id, IEnumerable <object> patchDocument, UpdateDigitalTwinOptions digitalTwinsUpdateOptions)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Patch;
            var uri = new RawRequestUriBuilder();

            uri.Reset(endpoint);
            uri.AppendPath("/digitaltwins/", false);
            uri.AppendPath(id, true);
            uri.AppendQuery("api-version", apiVersion, true);
            request.Uri = uri;
            if (digitalTwinsUpdateOptions?.IfMatch != null)
            {
                request.Headers.Add("If-Match", digitalTwinsUpdateOptions.IfMatch);
            }
            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("Content-Type", "application/json-patch+json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteStartArray();
            foreach (var item in patchDocument)
            {
                content.JsonWriter.WriteObjectValue(item);
            }
            content.JsonWriter.WriteEndArray();
            request.Content = content;
            return(message);
        }