1package databoxedge
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// OrdersClient is the client for the Orders methods of the Databoxedge service.
30type OrdersClient struct {
31	BaseClient
32}
33
34// NewOrdersClient creates an instance of the OrdersClient client.
35func NewOrdersClient(subscriptionID string) OrdersClient {
36	return NewOrdersClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewOrdersClientWithBaseURI creates an instance of the OrdersClient client.
40func NewOrdersClientWithBaseURI(baseURI string, subscriptionID string) OrdersClient {
41	return OrdersClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate sends the create or update request.
45// Parameters:
46// deviceName - the device name.
47// order - the order to be created or updated.
48// resourceGroupName - the resource group name.
49func (client OrdersClient) CreateOrUpdate(ctx context.Context, deviceName string, order Order, resourceGroupName string) (result OrdersCreateOrUpdateFuture, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.CreateOrUpdate")
52		defer func() {
53			sc := -1
54			if result.Response() != nil {
55				sc = result.Response().StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	if err := validation.Validate([]validation.Validation{
61		{TargetValue: order,
62			Constraints: []validation.Constraint{{Target: "order.OrderProperties", Name: validation.Null, Rule: false,
63				Chain: []validation.Constraint{{Target: "order.OrderProperties.ContactInformation", Name: validation.Null, Rule: true,
64					Chain: []validation.Constraint{{Target: "order.OrderProperties.ContactInformation.ContactPerson", Name: validation.Null, Rule: true, Chain: nil},
65						{Target: "order.OrderProperties.ContactInformation.CompanyName", Name: validation.Null, Rule: true, Chain: nil},
66						{Target: "order.OrderProperties.ContactInformation.Phone", Name: validation.Null, Rule: true, Chain: nil},
67						{Target: "order.OrderProperties.ContactInformation.EmailList", Name: validation.Null, Rule: true, Chain: nil},
68					}},
69					{Target: "order.OrderProperties.ShippingAddress", Name: validation.Null, Rule: true,
70						Chain: []validation.Constraint{{Target: "order.OrderProperties.ShippingAddress.AddressLine1", Name: validation.Null, Rule: true, Chain: nil},
71							{Target: "order.OrderProperties.ShippingAddress.PostalCode", Name: validation.Null, Rule: true, Chain: nil},
72							{Target: "order.OrderProperties.ShippingAddress.City", Name: validation.Null, Rule: true, Chain: nil},
73							{Target: "order.OrderProperties.ShippingAddress.State", Name: validation.Null, Rule: true, Chain: nil},
74							{Target: "order.OrderProperties.ShippingAddress.Country", Name: validation.Null, Rule: true, Chain: nil},
75						}},
76				}}}}}); err != nil {
77		return result, validation.NewError("databoxedge.OrdersClient", "CreateOrUpdate", err.Error())
78	}
79
80	req, err := client.CreateOrUpdatePreparer(ctx, deviceName, order, resourceGroupName)
81	if err != nil {
82		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "CreateOrUpdate", nil, "Failure preparing request")
83		return
84	}
85
86	result, err = client.CreateOrUpdateSender(req)
87	if err != nil {
88		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "CreateOrUpdate", result.Response(), "Failure sending request")
89		return
90	}
91
92	return
93}
94
95// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
96func (client OrdersClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, order Order, resourceGroupName string) (*http.Request, error) {
97	pathParameters := map[string]interface{}{
98		"deviceName":        autorest.Encode("path", deviceName),
99		"resourceGroupName": autorest.Encode("path", resourceGroupName),
100		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
101	}
102
103	const APIVersion = "2019-03-01"
104	queryParameters := map[string]interface{}{
105		"api-version": APIVersion,
106	}
107
108	preparer := autorest.CreatePreparer(
109		autorest.AsContentType("application/json; charset=utf-8"),
110		autorest.AsPut(),
111		autorest.WithBaseURL(client.BaseURI),
112		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders/default", pathParameters),
113		autorest.WithJSON(order),
114		autorest.WithQueryParameters(queryParameters))
115	return preparer.Prepare((&http.Request{}).WithContext(ctx))
116}
117
118// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
119// http.Response Body if it receives an error.
120func (client OrdersClient) CreateOrUpdateSender(req *http.Request) (future OrdersCreateOrUpdateFuture, err error) {
121	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
122	var resp *http.Response
123	resp, err = autorest.SendWithSender(client, req, sd...)
124	if err != nil {
125		return
126	}
127	future.Future, err = azure.NewFutureFromResponse(resp)
128	return
129}
130
131// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
132// closes the http.Response Body.
133func (client OrdersClient) CreateOrUpdateResponder(resp *http.Response) (result Order, err error) {
134	err = autorest.Respond(
135		resp,
136		client.ByInspecting(),
137		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
138		autorest.ByUnmarshallingJSON(&result),
139		autorest.ByClosing())
140	result.Response = autorest.Response{Response: resp}
141	return
142}
143
144// Delete sends the delete request.
145// Parameters:
146// deviceName - the device name.
147// resourceGroupName - the resource group name.
148func (client OrdersClient) Delete(ctx context.Context, deviceName string, resourceGroupName string) (result OrdersDeleteFuture, err error) {
149	if tracing.IsEnabled() {
150		ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.Delete")
151		defer func() {
152			sc := -1
153			if result.Response() != nil {
154				sc = result.Response().StatusCode
155			}
156			tracing.EndSpan(ctx, sc, err)
157		}()
158	}
159	req, err := client.DeletePreparer(ctx, deviceName, resourceGroupName)
160	if err != nil {
161		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Delete", nil, "Failure preparing request")
162		return
163	}
164
165	result, err = client.DeleteSender(req)
166	if err != nil {
167		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Delete", result.Response(), "Failure sending request")
168		return
169	}
170
171	return
172}
173
174// DeletePreparer prepares the Delete request.
175func (client OrdersClient) DeletePreparer(ctx context.Context, deviceName string, resourceGroupName string) (*http.Request, error) {
176	pathParameters := map[string]interface{}{
177		"deviceName":        autorest.Encode("path", deviceName),
178		"resourceGroupName": autorest.Encode("path", resourceGroupName),
179		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
180	}
181
182	const APIVersion = "2019-03-01"
183	queryParameters := map[string]interface{}{
184		"api-version": APIVersion,
185	}
186
187	preparer := autorest.CreatePreparer(
188		autorest.AsDelete(),
189		autorest.WithBaseURL(client.BaseURI),
190		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders/default", pathParameters),
191		autorest.WithQueryParameters(queryParameters))
192	return preparer.Prepare((&http.Request{}).WithContext(ctx))
193}
194
195// DeleteSender sends the Delete request. The method will close the
196// http.Response Body if it receives an error.
197func (client OrdersClient) DeleteSender(req *http.Request) (future OrdersDeleteFuture, err error) {
198	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
199	var resp *http.Response
200	resp, err = autorest.SendWithSender(client, req, sd...)
201	if err != nil {
202		return
203	}
204	future.Future, err = azure.NewFutureFromResponse(resp)
205	return
206}
207
208// DeleteResponder handles the response to the Delete request. The method always
209// closes the http.Response Body.
210func (client OrdersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
211	err = autorest.Respond(
212		resp,
213		client.ByInspecting(),
214		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
215		autorest.ByClosing())
216	result.Response = resp
217	return
218}
219
220// Get sends the get request.
221// Parameters:
222// deviceName - the device name.
223// resourceGroupName - the resource group name.
224func (client OrdersClient) Get(ctx context.Context, deviceName string, resourceGroupName string) (result Order, err error) {
225	if tracing.IsEnabled() {
226		ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.Get")
227		defer func() {
228			sc := -1
229			if result.Response.Response != nil {
230				sc = result.Response.Response.StatusCode
231			}
232			tracing.EndSpan(ctx, sc, err)
233		}()
234	}
235	req, err := client.GetPreparer(ctx, deviceName, resourceGroupName)
236	if err != nil {
237		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Get", nil, "Failure preparing request")
238		return
239	}
240
241	resp, err := client.GetSender(req)
242	if err != nil {
243		result.Response = autorest.Response{Response: resp}
244		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Get", resp, "Failure sending request")
245		return
246	}
247
248	result, err = client.GetResponder(resp)
249	if err != nil {
250		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "Get", resp, "Failure responding to request")
251	}
252
253	return
254}
255
256// GetPreparer prepares the Get request.
257func (client OrdersClient) GetPreparer(ctx context.Context, deviceName string, resourceGroupName string) (*http.Request, error) {
258	pathParameters := map[string]interface{}{
259		"deviceName":        autorest.Encode("path", deviceName),
260		"resourceGroupName": autorest.Encode("path", resourceGroupName),
261		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
262	}
263
264	const APIVersion = "2019-03-01"
265	queryParameters := map[string]interface{}{
266		"api-version": APIVersion,
267	}
268
269	preparer := autorest.CreatePreparer(
270		autorest.AsGet(),
271		autorest.WithBaseURL(client.BaseURI),
272		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders/default", pathParameters),
273		autorest.WithQueryParameters(queryParameters))
274	return preparer.Prepare((&http.Request{}).WithContext(ctx))
275}
276
277// GetSender sends the Get request. The method will close the
278// http.Response Body if it receives an error.
279func (client OrdersClient) GetSender(req *http.Request) (*http.Response, error) {
280	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
281	return autorest.SendWithSender(client, req, sd...)
282}
283
284// GetResponder handles the response to the Get request. The method always
285// closes the http.Response Body.
286func (client OrdersClient) GetResponder(resp *http.Response) (result Order, err error) {
287	err = autorest.Respond(
288		resp,
289		client.ByInspecting(),
290		azure.WithErrorUnlessStatusCode(http.StatusOK),
291		autorest.ByUnmarshallingJSON(&result),
292		autorest.ByClosing())
293	result.Response = autorest.Response{Response: resp}
294	return
295}
296
297// ListByDataBoxEdgeDevice sends the list by data box edge device request.
298// Parameters:
299// deviceName - the device name.
300// resourceGroupName - the resource group name.
301func (client OrdersClient) ListByDataBoxEdgeDevice(ctx context.Context, deviceName string, resourceGroupName string) (result OrderListPage, err error) {
302	if tracing.IsEnabled() {
303		ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.ListByDataBoxEdgeDevice")
304		defer func() {
305			sc := -1
306			if result.ol.Response.Response != nil {
307				sc = result.ol.Response.Response.StatusCode
308			}
309			tracing.EndSpan(ctx, sc, err)
310		}()
311	}
312	result.fn = client.listByDataBoxEdgeDeviceNextResults
313	req, err := client.ListByDataBoxEdgeDevicePreparer(ctx, deviceName, resourceGroupName)
314	if err != nil {
315		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "ListByDataBoxEdgeDevice", nil, "Failure preparing request")
316		return
317	}
318
319	resp, err := client.ListByDataBoxEdgeDeviceSender(req)
320	if err != nil {
321		result.ol.Response = autorest.Response{Response: resp}
322		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "ListByDataBoxEdgeDevice", resp, "Failure sending request")
323		return
324	}
325
326	result.ol, err = client.ListByDataBoxEdgeDeviceResponder(resp)
327	if err != nil {
328		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "ListByDataBoxEdgeDevice", resp, "Failure responding to request")
329	}
330
331	return
332}
333
334// ListByDataBoxEdgeDevicePreparer prepares the ListByDataBoxEdgeDevice request.
335func (client OrdersClient) ListByDataBoxEdgeDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string) (*http.Request, error) {
336	pathParameters := map[string]interface{}{
337		"deviceName":        autorest.Encode("path", deviceName),
338		"resourceGroupName": autorest.Encode("path", resourceGroupName),
339		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
340	}
341
342	const APIVersion = "2019-03-01"
343	queryParameters := map[string]interface{}{
344		"api-version": APIVersion,
345	}
346
347	preparer := autorest.CreatePreparer(
348		autorest.AsGet(),
349		autorest.WithBaseURL(client.BaseURI),
350		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/orders", pathParameters),
351		autorest.WithQueryParameters(queryParameters))
352	return preparer.Prepare((&http.Request{}).WithContext(ctx))
353}
354
355// ListByDataBoxEdgeDeviceSender sends the ListByDataBoxEdgeDevice request. The method will close the
356// http.Response Body if it receives an error.
357func (client OrdersClient) ListByDataBoxEdgeDeviceSender(req *http.Request) (*http.Response, error) {
358	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
359	return autorest.SendWithSender(client, req, sd...)
360}
361
362// ListByDataBoxEdgeDeviceResponder handles the response to the ListByDataBoxEdgeDevice request. The method always
363// closes the http.Response Body.
364func (client OrdersClient) ListByDataBoxEdgeDeviceResponder(resp *http.Response) (result OrderList, err error) {
365	err = autorest.Respond(
366		resp,
367		client.ByInspecting(),
368		azure.WithErrorUnlessStatusCode(http.StatusOK),
369		autorest.ByUnmarshallingJSON(&result),
370		autorest.ByClosing())
371	result.Response = autorest.Response{Response: resp}
372	return
373}
374
375// listByDataBoxEdgeDeviceNextResults retrieves the next set of results, if any.
376func (client OrdersClient) listByDataBoxEdgeDeviceNextResults(ctx context.Context, lastResults OrderList) (result OrderList, err error) {
377	req, err := lastResults.orderListPreparer(ctx)
378	if err != nil {
379		return result, autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "listByDataBoxEdgeDeviceNextResults", nil, "Failure preparing next results request")
380	}
381	if req == nil {
382		return
383	}
384	resp, err := client.ListByDataBoxEdgeDeviceSender(req)
385	if err != nil {
386		result.Response = autorest.Response{Response: resp}
387		return result, autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "listByDataBoxEdgeDeviceNextResults", resp, "Failure sending next results request")
388	}
389	result, err = client.ListByDataBoxEdgeDeviceResponder(resp)
390	if err != nil {
391		err = autorest.NewErrorWithError(err, "databoxedge.OrdersClient", "listByDataBoxEdgeDeviceNextResults", resp, "Failure responding to next results request")
392	}
393	return
394}
395
396// ListByDataBoxEdgeDeviceComplete enumerates all values, automatically crossing page boundaries as required.
397func (client OrdersClient) ListByDataBoxEdgeDeviceComplete(ctx context.Context, deviceName string, resourceGroupName string) (result OrderListIterator, err error) {
398	if tracing.IsEnabled() {
399		ctx = tracing.StartSpan(ctx, fqdn+"/OrdersClient.ListByDataBoxEdgeDevice")
400		defer func() {
401			sc := -1
402			if result.Response().Response.Response != nil {
403				sc = result.page.Response().Response.Response.StatusCode
404			}
405			tracing.EndSpan(ctx, sc, err)
406		}()
407	}
408	result.page, err = client.ListByDataBoxEdgeDevice(ctx, deviceName, resourceGroupName)
409	return
410}
411