1package digitaltwins
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// Client is the azure Digital Twins Client for managing DigitalTwinsInstance
30type Client struct {
31	BaseClient
32}
33
34// NewClient creates an instance of the Client client.
35func NewClient(subscriptionID string) Client {
36	return NewClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewClientWithBaseURI creates an instance of the Client client using a custom endpoint.  Use this when interacting
40// with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewClientWithBaseURI(baseURI string, subscriptionID string) Client {
42	return Client{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CheckNameAvailability check if a DigitalTwinsInstance name is available.
46// Parameters:
47// location - location of DigitalTwinsInstance.
48// digitalTwinsInstanceCheckName - set the name parameter in the DigitalTwinsInstanceCheckName structure to the
49// name of the DigitalTwinsInstance to check.
50func (client Client) CheckNameAvailability(ctx context.Context, location string, digitalTwinsInstanceCheckName CheckNameRequest) (result CheckNameResult, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/Client.CheckNameAvailability")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	if err := validation.Validate([]validation.Validation{
62		{TargetValue: location,
63			Constraints: []validation.Constraint{{Target: "location", Name: validation.MinLength, Rule: 3, Chain: nil}}},
64		{TargetValue: digitalTwinsInstanceCheckName,
65			Constraints: []validation.Constraint{{Target: "digitalTwinsInstanceCheckName.Name", Name: validation.Null, Rule: true, Chain: nil},
66				{Target: "digitalTwinsInstanceCheckName.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
67		return result, validation.NewError("digitaltwins.Client", "CheckNameAvailability", err.Error())
68	}
69
70	req, err := client.CheckNameAvailabilityPreparer(ctx, location, digitalTwinsInstanceCheckName)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CheckNameAvailability", nil, "Failure preparing request")
73		return
74	}
75
76	resp, err := client.CheckNameAvailabilitySender(req)
77	if err != nil {
78		result.Response = autorest.Response{Response: resp}
79		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CheckNameAvailability", resp, "Failure sending request")
80		return
81	}
82
83	result, err = client.CheckNameAvailabilityResponder(resp)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CheckNameAvailability", resp, "Failure responding to request")
86		return
87	}
88
89	return
90}
91
92// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
93func (client Client) CheckNameAvailabilityPreparer(ctx context.Context, location string, digitalTwinsInstanceCheckName CheckNameRequest) (*http.Request, error) {
94	pathParameters := map[string]interface{}{
95		"location":       autorest.Encode("path", location),
96		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
97	}
98
99	const APIVersion = "2020-10-31"
100	queryParameters := map[string]interface{}{
101		"api-version": APIVersion,
102	}
103
104	preparer := autorest.CreatePreparer(
105		autorest.AsContentType("application/json; charset=utf-8"),
106		autorest.AsPost(),
107		autorest.WithBaseURL(client.BaseURI),
108		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DigitalTwins/locations/{location}/checkNameAvailability", pathParameters),
109		autorest.WithJSON(digitalTwinsInstanceCheckName),
110		autorest.WithQueryParameters(queryParameters))
111	return preparer.Prepare((&http.Request{}).WithContext(ctx))
112}
113
114// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
115// http.Response Body if it receives an error.
116func (client Client) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
117	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
118}
119
120// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
121// closes the http.Response Body.
122func (client Client) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameResult, err error) {
123	err = autorest.Respond(
124		resp,
125		azure.WithErrorUnlessStatusCode(http.StatusOK),
126		autorest.ByUnmarshallingJSON(&result),
127		autorest.ByClosing())
128	result.Response = autorest.Response{Response: resp}
129	return
130}
131
132// CreateOrUpdate create or update the metadata of a DigitalTwinsInstance. The usual pattern to modify a property is to
133// retrieve the DigitalTwinsInstance and security metadata, and then combine them with the modified values in a new
134// body to update the DigitalTwinsInstance.
135// Parameters:
136// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance.
137// resourceName - the name of the DigitalTwinsInstance.
138// digitalTwinsCreate - the DigitalTwinsInstance and security metadata.
139func (client Client) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsCreate Description) (result CreateOrUpdateFuture, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/Client.CreateOrUpdate")
142		defer func() {
143			sc := -1
144			if result.Response() != nil {
145				sc = result.Response().StatusCode
146			}
147			tracing.EndSpan(ctx, sc, err)
148		}()
149	}
150	if err := validation.Validate([]validation.Validation{
151		{TargetValue: resourceGroupName,
152			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
153				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
154		{TargetValue: resourceName,
155			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
156				{Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
157		return result, validation.NewError("digitaltwins.Client", "CreateOrUpdate", err.Error())
158	}
159
160	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceName, digitalTwinsCreate)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CreateOrUpdate", nil, "Failure preparing request")
163		return
164	}
165
166	result, err = client.CreateOrUpdateSender(req)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CreateOrUpdate", nil, "Failure sending request")
169		return
170	}
171
172	return
173}
174
175// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
176func (client Client) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsCreate Description) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"resourceGroupName": autorest.Encode("path", resourceGroupName),
179		"resourceName":      autorest.Encode("path", resourceName),
180		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
181	}
182
183	const APIVersion = "2020-10-31"
184	queryParameters := map[string]interface{}{
185		"api-version": APIVersion,
186	}
187
188	preparer := autorest.CreatePreparer(
189		autorest.AsContentType("application/json; charset=utf-8"),
190		autorest.AsPut(),
191		autorest.WithBaseURL(client.BaseURI),
192		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters),
193		autorest.WithJSON(digitalTwinsCreate),
194		autorest.WithQueryParameters(queryParameters))
195	return preparer.Prepare((&http.Request{}).WithContext(ctx))
196}
197
198// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
199// http.Response Body if it receives an error.
200func (client Client) CreateOrUpdateSender(req *http.Request) (future CreateOrUpdateFuture, err error) {
201	var resp *http.Response
202	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
203	if err != nil {
204		return
205	}
206	var azf azure.Future
207	azf, err = azure.NewFutureFromResponse(resp)
208	future.FutureAPI = &azf
209	future.Result = func(client Client) (d Description, err error) {
210		var done bool
211		done, err = future.DoneWithContext(context.Background(), client)
212		if err != nil {
213			err = autorest.NewErrorWithError(err, "digitaltwins.CreateOrUpdateFuture", "Result", future.Response(), "Polling failure")
214			return
215		}
216		if !done {
217			err = azure.NewAsyncOpIncompleteError("digitaltwins.CreateOrUpdateFuture")
218			return
219		}
220		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
221		if d.Response.Response, err = future.GetResult(sender); err == nil && d.Response.Response.StatusCode != http.StatusNoContent {
222			d, err = client.CreateOrUpdateResponder(d.Response.Response)
223			if err != nil {
224				err = autorest.NewErrorWithError(err, "digitaltwins.CreateOrUpdateFuture", "Result", d.Response.Response, "Failure responding to request")
225			}
226		}
227		return
228	}
229	return
230}
231
232// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
233// closes the http.Response Body.
234func (client Client) CreateOrUpdateResponder(resp *http.Response) (result Description, err error) {
235	err = autorest.Respond(
236		resp,
237		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
238		autorest.ByUnmarshallingJSON(&result),
239		autorest.ByClosing())
240	result.Response = autorest.Response{Response: resp}
241	return
242}
243
244// Delete delete a DigitalTwinsInstance.
245// Parameters:
246// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance.
247// resourceName - the name of the DigitalTwinsInstance.
248func (client Client) Delete(ctx context.Context, resourceGroupName string, resourceName string) (result DeleteFuture, err error) {
249	if tracing.IsEnabled() {
250		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Delete")
251		defer func() {
252			sc := -1
253			if result.Response() != nil {
254				sc = result.Response().StatusCode
255			}
256			tracing.EndSpan(ctx, sc, err)
257		}()
258	}
259	if err := validation.Validate([]validation.Validation{
260		{TargetValue: resourceGroupName,
261			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
262				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
263		{TargetValue: resourceName,
264			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
265				{Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
266		return result, validation.NewError("digitaltwins.Client", "Delete", err.Error())
267	}
268
269	req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName)
270	if err != nil {
271		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Delete", nil, "Failure preparing request")
272		return
273	}
274
275	result, err = client.DeleteSender(req)
276	if err != nil {
277		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Delete", nil, "Failure sending request")
278		return
279	}
280
281	return
282}
283
284// DeletePreparer prepares the Delete request.
285func (client Client) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
286	pathParameters := map[string]interface{}{
287		"resourceGroupName": autorest.Encode("path", resourceGroupName),
288		"resourceName":      autorest.Encode("path", resourceName),
289		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
290	}
291
292	const APIVersion = "2020-10-31"
293	queryParameters := map[string]interface{}{
294		"api-version": APIVersion,
295	}
296
297	preparer := autorest.CreatePreparer(
298		autorest.AsDelete(),
299		autorest.WithBaseURL(client.BaseURI),
300		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters),
301		autorest.WithQueryParameters(queryParameters))
302	return preparer.Prepare((&http.Request{}).WithContext(ctx))
303}
304
305// DeleteSender sends the Delete request. The method will close the
306// http.Response Body if it receives an error.
307func (client Client) DeleteSender(req *http.Request) (future DeleteFuture, err error) {
308	var resp *http.Response
309	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
310	if err != nil {
311		return
312	}
313	var azf azure.Future
314	azf, err = azure.NewFutureFromResponse(resp)
315	future.FutureAPI = &azf
316	future.Result = func(client Client) (d Description, err error) {
317		var done bool
318		done, err = future.DoneWithContext(context.Background(), client)
319		if err != nil {
320			err = autorest.NewErrorWithError(err, "digitaltwins.DeleteFuture", "Result", future.Response(), "Polling failure")
321			return
322		}
323		if !done {
324			err = azure.NewAsyncOpIncompleteError("digitaltwins.DeleteFuture")
325			return
326		}
327		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
328		if d.Response.Response, err = future.GetResult(sender); err == nil && d.Response.Response.StatusCode != http.StatusNoContent {
329			d, err = client.DeleteResponder(d.Response.Response)
330			if err != nil {
331				err = autorest.NewErrorWithError(err, "digitaltwins.DeleteFuture", "Result", d.Response.Response, "Failure responding to request")
332			}
333		}
334		return
335	}
336	return
337}
338
339// DeleteResponder handles the response to the Delete request. The method always
340// closes the http.Response Body.
341func (client Client) DeleteResponder(resp *http.Response) (result Description, err error) {
342	err = autorest.Respond(
343		resp,
344		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
345		autorest.ByUnmarshallingJSON(&result),
346		autorest.ByClosing())
347	result.Response = autorest.Response{Response: resp}
348	return
349}
350
351// Get get DigitalTwinsInstances resource.
352// Parameters:
353// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance.
354// resourceName - the name of the DigitalTwinsInstance.
355func (client Client) Get(ctx context.Context, resourceGroupName string, resourceName string) (result Description, err error) {
356	if tracing.IsEnabled() {
357		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get")
358		defer func() {
359			sc := -1
360			if result.Response.Response != nil {
361				sc = result.Response.Response.StatusCode
362			}
363			tracing.EndSpan(ctx, sc, err)
364		}()
365	}
366	if err := validation.Validate([]validation.Validation{
367		{TargetValue: resourceGroupName,
368			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
369				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
370		{TargetValue: resourceName,
371			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
372				{Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
373		return result, validation.NewError("digitaltwins.Client", "Get", err.Error())
374	}
375
376	req, err := client.GetPreparer(ctx, resourceGroupName, resourceName)
377	if err != nil {
378		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Get", nil, "Failure preparing request")
379		return
380	}
381
382	resp, err := client.GetSender(req)
383	if err != nil {
384		result.Response = autorest.Response{Response: resp}
385		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Get", resp, "Failure sending request")
386		return
387	}
388
389	result, err = client.GetResponder(resp)
390	if err != nil {
391		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Get", resp, "Failure responding to request")
392		return
393	}
394
395	return
396}
397
398// GetPreparer prepares the Get request.
399func (client Client) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
400	pathParameters := map[string]interface{}{
401		"resourceGroupName": autorest.Encode("path", resourceGroupName),
402		"resourceName":      autorest.Encode("path", resourceName),
403		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
404	}
405
406	const APIVersion = "2020-10-31"
407	queryParameters := map[string]interface{}{
408		"api-version": APIVersion,
409	}
410
411	preparer := autorest.CreatePreparer(
412		autorest.AsGet(),
413		autorest.WithBaseURL(client.BaseURI),
414		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters),
415		autorest.WithQueryParameters(queryParameters))
416	return preparer.Prepare((&http.Request{}).WithContext(ctx))
417}
418
419// GetSender sends the Get request. The method will close the
420// http.Response Body if it receives an error.
421func (client Client) GetSender(req *http.Request) (*http.Response, error) {
422	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
423}
424
425// GetResponder handles the response to the Get request. The method always
426// closes the http.Response Body.
427func (client Client) GetResponder(resp *http.Response) (result Description, err error) {
428	err = autorest.Respond(
429		resp,
430		azure.WithErrorUnlessStatusCode(http.StatusOK),
431		autorest.ByUnmarshallingJSON(&result),
432		autorest.ByClosing())
433	result.Response = autorest.Response{Response: resp}
434	return
435}
436
437// List get all the DigitalTwinsInstances in a subscription.
438func (client Client) List(ctx context.Context) (result DescriptionListResultPage, err error) {
439	if tracing.IsEnabled() {
440		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
441		defer func() {
442			sc := -1
443			if result.dlr.Response.Response != nil {
444				sc = result.dlr.Response.Response.StatusCode
445			}
446			tracing.EndSpan(ctx, sc, err)
447		}()
448	}
449	result.fn = client.listNextResults
450	req, err := client.ListPreparer(ctx)
451	if err != nil {
452		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "List", nil, "Failure preparing request")
453		return
454	}
455
456	resp, err := client.ListSender(req)
457	if err != nil {
458		result.dlr.Response = autorest.Response{Response: resp}
459		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "List", resp, "Failure sending request")
460		return
461	}
462
463	result.dlr, err = client.ListResponder(resp)
464	if err != nil {
465		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "List", resp, "Failure responding to request")
466		return
467	}
468	if result.dlr.hasNextLink() && result.dlr.IsEmpty() {
469		err = result.NextWithContext(ctx)
470		return
471	}
472
473	return
474}
475
476// ListPreparer prepares the List request.
477func (client Client) ListPreparer(ctx context.Context) (*http.Request, error) {
478	pathParameters := map[string]interface{}{
479		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
480	}
481
482	const APIVersion = "2020-10-31"
483	queryParameters := map[string]interface{}{
484		"api-version": APIVersion,
485	}
486
487	preparer := autorest.CreatePreparer(
488		autorest.AsGet(),
489		autorest.WithBaseURL(client.BaseURI),
490		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DigitalTwins/digitalTwinsInstances", pathParameters),
491		autorest.WithQueryParameters(queryParameters))
492	return preparer.Prepare((&http.Request{}).WithContext(ctx))
493}
494
495// ListSender sends the List request. The method will close the
496// http.Response Body if it receives an error.
497func (client Client) ListSender(req *http.Request) (*http.Response, error) {
498	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
499}
500
501// ListResponder handles the response to the List request. The method always
502// closes the http.Response Body.
503func (client Client) ListResponder(resp *http.Response) (result DescriptionListResult, err error) {
504	err = autorest.Respond(
505		resp,
506		azure.WithErrorUnlessStatusCode(http.StatusOK),
507		autorest.ByUnmarshallingJSON(&result),
508		autorest.ByClosing())
509	result.Response = autorest.Response{Response: resp}
510	return
511}
512
513// listNextResults retrieves the next set of results, if any.
514func (client Client) listNextResults(ctx context.Context, lastResults DescriptionListResult) (result DescriptionListResult, err error) {
515	req, err := lastResults.descriptionListResultPreparer(ctx)
516	if err != nil {
517		return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listNextResults", nil, "Failure preparing next results request")
518	}
519	if req == nil {
520		return
521	}
522	resp, err := client.ListSender(req)
523	if err != nil {
524		result.Response = autorest.Response{Response: resp}
525		return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listNextResults", resp, "Failure sending next results request")
526	}
527	result, err = client.ListResponder(resp)
528	if err != nil {
529		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "listNextResults", resp, "Failure responding to next results request")
530	}
531	return
532}
533
534// ListComplete enumerates all values, automatically crossing page boundaries as required.
535func (client Client) ListComplete(ctx context.Context) (result DescriptionListResultIterator, err error) {
536	if tracing.IsEnabled() {
537		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
538		defer func() {
539			sc := -1
540			if result.Response().Response.Response != nil {
541				sc = result.page.Response().Response.Response.StatusCode
542			}
543			tracing.EndSpan(ctx, sc, err)
544		}()
545	}
546	result.page, err = client.List(ctx)
547	return
548}
549
550// ListByResourceGroup get all the DigitalTwinsInstances in a resource group.
551// Parameters:
552// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance.
553func (client Client) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result DescriptionListResultPage, err error) {
554	if tracing.IsEnabled() {
555		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup")
556		defer func() {
557			sc := -1
558			if result.dlr.Response.Response != nil {
559				sc = result.dlr.Response.Response.StatusCode
560			}
561			tracing.EndSpan(ctx, sc, err)
562		}()
563	}
564	if err := validation.Validate([]validation.Validation{
565		{TargetValue: resourceGroupName,
566			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
567				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
568		return result, validation.NewError("digitaltwins.Client", "ListByResourceGroup", err.Error())
569	}
570
571	result.fn = client.listByResourceGroupNextResults
572	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
573	if err != nil {
574		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListByResourceGroup", nil, "Failure preparing request")
575		return
576	}
577
578	resp, err := client.ListByResourceGroupSender(req)
579	if err != nil {
580		result.dlr.Response = autorest.Response{Response: resp}
581		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListByResourceGroup", resp, "Failure sending request")
582		return
583	}
584
585	result.dlr, err = client.ListByResourceGroupResponder(resp)
586	if err != nil {
587		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListByResourceGroup", resp, "Failure responding to request")
588		return
589	}
590	if result.dlr.hasNextLink() && result.dlr.IsEmpty() {
591		err = result.NextWithContext(ctx)
592		return
593	}
594
595	return
596}
597
598// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
599func (client Client) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
600	pathParameters := map[string]interface{}{
601		"resourceGroupName": autorest.Encode("path", resourceGroupName),
602		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
603	}
604
605	const APIVersion = "2020-10-31"
606	queryParameters := map[string]interface{}{
607		"api-version": APIVersion,
608	}
609
610	preparer := autorest.CreatePreparer(
611		autorest.AsGet(),
612		autorest.WithBaseURL(client.BaseURI),
613		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances", pathParameters),
614		autorest.WithQueryParameters(queryParameters))
615	return preparer.Prepare((&http.Request{}).WithContext(ctx))
616}
617
618// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
619// http.Response Body if it receives an error.
620func (client Client) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
621	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
622}
623
624// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
625// closes the http.Response Body.
626func (client Client) ListByResourceGroupResponder(resp *http.Response) (result DescriptionListResult, err error) {
627	err = autorest.Respond(
628		resp,
629		azure.WithErrorUnlessStatusCode(http.StatusOK),
630		autorest.ByUnmarshallingJSON(&result),
631		autorest.ByClosing())
632	result.Response = autorest.Response{Response: resp}
633	return
634}
635
636// listByResourceGroupNextResults retrieves the next set of results, if any.
637func (client Client) listByResourceGroupNextResults(ctx context.Context, lastResults DescriptionListResult) (result DescriptionListResult, err error) {
638	req, err := lastResults.descriptionListResultPreparer(ctx)
639	if err != nil {
640		return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
641	}
642	if req == nil {
643		return
644	}
645	resp, err := client.ListByResourceGroupSender(req)
646	if err != nil {
647		result.Response = autorest.Response{Response: resp}
648		return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listByResourceGroupNextResults", resp, "Failure sending next results request")
649	}
650	result, err = client.ListByResourceGroupResponder(resp)
651	if err != nil {
652		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
653	}
654	return
655}
656
657// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
658func (client Client) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result DescriptionListResultIterator, err error) {
659	if tracing.IsEnabled() {
660		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup")
661		defer func() {
662			sc := -1
663			if result.Response().Response.Response != nil {
664				sc = result.page.Response().Response.Response.StatusCode
665			}
666			tracing.EndSpan(ctx, sc, err)
667		}()
668	}
669	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
670	return
671}
672
673// Update update metadata of DigitalTwinsInstance.
674// Parameters:
675// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance.
676// resourceName - the name of the DigitalTwinsInstance.
677// digitalTwinsPatchDescription - the DigitalTwinsInstance and security metadata.
678func (client Client) Update(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsPatchDescription PatchDescription) (result Description, err error) {
679	if tracing.IsEnabled() {
680		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Update")
681		defer func() {
682			sc := -1
683			if result.Response.Response != nil {
684				sc = result.Response.Response.StatusCode
685			}
686			tracing.EndSpan(ctx, sc, err)
687		}()
688	}
689	if err := validation.Validate([]validation.Validation{
690		{TargetValue: resourceGroupName,
691			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
692				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
693		{TargetValue: resourceName,
694			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
695				{Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
696		return result, validation.NewError("digitaltwins.Client", "Update", err.Error())
697	}
698
699	req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, digitalTwinsPatchDescription)
700	if err != nil {
701		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", nil, "Failure preparing request")
702		return
703	}
704
705	resp, err := client.UpdateSender(req)
706	if err != nil {
707		result.Response = autorest.Response{Response: resp}
708		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", resp, "Failure sending request")
709		return
710	}
711
712	result, err = client.UpdateResponder(resp)
713	if err != nil {
714		err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", resp, "Failure responding to request")
715		return
716	}
717
718	return
719}
720
721// UpdatePreparer prepares the Update request.
722func (client Client) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsPatchDescription PatchDescription) (*http.Request, error) {
723	pathParameters := map[string]interface{}{
724		"resourceGroupName": autorest.Encode("path", resourceGroupName),
725		"resourceName":      autorest.Encode("path", resourceName),
726		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
727	}
728
729	const APIVersion = "2020-10-31"
730	queryParameters := map[string]interface{}{
731		"api-version": APIVersion,
732	}
733
734	preparer := autorest.CreatePreparer(
735		autorest.AsContentType("application/json; charset=utf-8"),
736		autorest.AsPatch(),
737		autorest.WithBaseURL(client.BaseURI),
738		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters),
739		autorest.WithJSON(digitalTwinsPatchDescription),
740		autorest.WithQueryParameters(queryParameters))
741	return preparer.Prepare((&http.Request{}).WithContext(ctx))
742}
743
744// UpdateSender sends the Update request. The method will close the
745// http.Response Body if it receives an error.
746func (client Client) UpdateSender(req *http.Request) (*http.Response, error) {
747	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
748}
749
750// UpdateResponder handles the response to the Update request. The method always
751// closes the http.Response Body.
752func (client Client) UpdateResponder(resp *http.Response) (result Description, err error) {
753	err = autorest.Respond(
754		resp,
755		azure.WithErrorUnlessStatusCode(http.StatusOK),
756		autorest.ByUnmarshallingJSON(&result),
757		autorest.ByClosing())
758	result.Response = autorest.Response{Response: resp}
759	return
760}
761