1package hybridnetwork
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// NetworkFunctionVendorSkusClient is the client for the NetworkFunctionVendorSkus methods of the Hybridnetwork
30// service.
31type NetworkFunctionVendorSkusClient struct {
32	BaseClient
33}
34
35// NewNetworkFunctionVendorSkusClient creates an instance of the NetworkFunctionVendorSkusClient client.
36func NewNetworkFunctionVendorSkusClient(subscriptionID string) NetworkFunctionVendorSkusClient {
37	return NewNetworkFunctionVendorSkusClientWithBaseURI(DefaultBaseURI, subscriptionID)
38}
39
40// NewNetworkFunctionVendorSkusClientWithBaseURI creates an instance of the NetworkFunctionVendorSkusClient client
41// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
42// clouds, Azure stack).
43func NewNetworkFunctionVendorSkusClientWithBaseURI(baseURI string, subscriptionID string) NetworkFunctionVendorSkusClient {
44	return NetworkFunctionVendorSkusClient{NewWithBaseURI(baseURI, subscriptionID)}
45}
46
47// ListBySku lists information about network function vendor sku details.
48// Parameters:
49// vendorName - the name of the network function vendor.
50// vendorSkuName - the name of the network function sku.
51func (client NetworkFunctionVendorSkusClient) ListBySku(ctx context.Context, vendorName string, vendorSkuName string) (result NetworkFunctionSkuDetailsPage, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/NetworkFunctionVendorSkusClient.ListBySku")
54		defer func() {
55			sc := -1
56			if result.nfsd.Response.Response != nil {
57				sc = result.nfsd.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	if err := validation.Validate([]validation.Validation{
63		{TargetValue: client.SubscriptionID,
64			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
65		return result, validation.NewError("hybridnetwork.NetworkFunctionVendorSkusClient", "ListBySku", err.Error())
66	}
67
68	result.fn = client.listBySkuNextResults
69	req, err := client.ListBySkuPreparer(ctx, vendorName, vendorSkuName)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "ListBySku", nil, "Failure preparing request")
72		return
73	}
74
75	resp, err := client.ListBySkuSender(req)
76	if err != nil {
77		result.nfsd.Response = autorest.Response{Response: resp}
78		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "ListBySku", resp, "Failure sending request")
79		return
80	}
81
82	result.nfsd, err = client.ListBySkuResponder(resp)
83	if err != nil {
84		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "ListBySku", resp, "Failure responding to request")
85		return
86	}
87	if result.nfsd.hasNextLink() && result.nfsd.IsEmpty() {
88		err = result.NextWithContext(ctx)
89		return
90	}
91
92	return
93}
94
95// ListBySkuPreparer prepares the ListBySku request.
96func (client NetworkFunctionVendorSkusClient) ListBySkuPreparer(ctx context.Context, vendorName string, vendorSkuName string) (*http.Request, error) {
97	pathParameters := map[string]interface{}{
98		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
99		"vendorName":     autorest.Encode("path", vendorName),
100		"vendorSkuName":  autorest.Encode("path", vendorSkuName),
101	}
102
103	const APIVersion = "2020-01-01-preview"
104	queryParameters := map[string]interface{}{
105		"api-version": APIVersion,
106	}
107
108	preparer := autorest.CreatePreparer(
109		autorest.AsGet(),
110		autorest.WithBaseURL(client.BaseURI),
111		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctionVendors/{vendorName}/vendorSkus/{vendorSkuName}", pathParameters),
112		autorest.WithQueryParameters(queryParameters))
113	return preparer.Prepare((&http.Request{}).WithContext(ctx))
114}
115
116// ListBySkuSender sends the ListBySku request. The method will close the
117// http.Response Body if it receives an error.
118func (client NetworkFunctionVendorSkusClient) ListBySkuSender(req *http.Request) (*http.Response, error) {
119	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
120}
121
122// ListBySkuResponder handles the response to the ListBySku request. The method always
123// closes the http.Response Body.
124func (client NetworkFunctionVendorSkusClient) ListBySkuResponder(resp *http.Response) (result NetworkFunctionSkuDetails, err error) {
125	err = autorest.Respond(
126		resp,
127		azure.WithErrorUnlessStatusCode(http.StatusOK),
128		autorest.ByUnmarshallingJSON(&result),
129		autorest.ByClosing())
130	result.Response = autorest.Response{Response: resp}
131	return
132}
133
134// listBySkuNextResults retrieves the next set of results, if any.
135func (client NetworkFunctionVendorSkusClient) listBySkuNextResults(ctx context.Context, lastResults NetworkFunctionSkuDetails) (result NetworkFunctionSkuDetails, err error) {
136	req, err := lastResults.networkFunctionSkuDetailsPreparer(ctx)
137	if err != nil {
138		return result, autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "listBySkuNextResults", nil, "Failure preparing next results request")
139	}
140	if req == nil {
141		return
142	}
143	resp, err := client.ListBySkuSender(req)
144	if err != nil {
145		result.Response = autorest.Response{Response: resp}
146		return result, autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "listBySkuNextResults", resp, "Failure sending next results request")
147	}
148	result, err = client.ListBySkuResponder(resp)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "listBySkuNextResults", resp, "Failure responding to next results request")
151	}
152	return
153}
154
155// ListBySkuComplete enumerates all values, automatically crossing page boundaries as required.
156func (client NetworkFunctionVendorSkusClient) ListBySkuComplete(ctx context.Context, vendorName string, vendorSkuName string) (result NetworkFunctionSkuDetailsIterator, err error) {
157	if tracing.IsEnabled() {
158		ctx = tracing.StartSpan(ctx, fqdn+"/NetworkFunctionVendorSkusClient.ListBySku")
159		defer func() {
160			sc := -1
161			if result.Response().Response.Response != nil {
162				sc = result.page.Response().Response.Response.StatusCode
163			}
164			tracing.EndSpan(ctx, sc, err)
165		}()
166	}
167	result.page, err = client.ListBySku(ctx, vendorName, vendorSkuName)
168	return
169}
170
171// ListByVendor lists all network function vendor sku details in a vendor.
172// Parameters:
173// vendorName - the name of the network function vendor.
174func (client NetworkFunctionVendorSkusClient) ListByVendor(ctx context.Context, vendorName string) (result NetworkFunctionSkuListResultPage, err error) {
175	if tracing.IsEnabled() {
176		ctx = tracing.StartSpan(ctx, fqdn+"/NetworkFunctionVendorSkusClient.ListByVendor")
177		defer func() {
178			sc := -1
179			if result.nfslr.Response.Response != nil {
180				sc = result.nfslr.Response.Response.StatusCode
181			}
182			tracing.EndSpan(ctx, sc, err)
183		}()
184	}
185	if err := validation.Validate([]validation.Validation{
186		{TargetValue: client.SubscriptionID,
187			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
188		return result, validation.NewError("hybridnetwork.NetworkFunctionVendorSkusClient", "ListByVendor", err.Error())
189	}
190
191	result.fn = client.listByVendorNextResults
192	req, err := client.ListByVendorPreparer(ctx, vendorName)
193	if err != nil {
194		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "ListByVendor", nil, "Failure preparing request")
195		return
196	}
197
198	resp, err := client.ListByVendorSender(req)
199	if err != nil {
200		result.nfslr.Response = autorest.Response{Response: resp}
201		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "ListByVendor", resp, "Failure sending request")
202		return
203	}
204
205	result.nfslr, err = client.ListByVendorResponder(resp)
206	if err != nil {
207		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "ListByVendor", resp, "Failure responding to request")
208		return
209	}
210	if result.nfslr.hasNextLink() && result.nfslr.IsEmpty() {
211		err = result.NextWithContext(ctx)
212		return
213	}
214
215	return
216}
217
218// ListByVendorPreparer prepares the ListByVendor request.
219func (client NetworkFunctionVendorSkusClient) ListByVendorPreparer(ctx context.Context, vendorName string) (*http.Request, error) {
220	pathParameters := map[string]interface{}{
221		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
222		"vendorName":     autorest.Encode("path", vendorName),
223	}
224
225	const APIVersion = "2020-01-01-preview"
226	queryParameters := map[string]interface{}{
227		"api-version": APIVersion,
228	}
229
230	preparer := autorest.CreatePreparer(
231		autorest.AsGet(),
232		autorest.WithBaseURL(client.BaseURI),
233		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctionVendors/{vendorName}/vendorSkus", pathParameters),
234		autorest.WithQueryParameters(queryParameters))
235	return preparer.Prepare((&http.Request{}).WithContext(ctx))
236}
237
238// ListByVendorSender sends the ListByVendor request. The method will close the
239// http.Response Body if it receives an error.
240func (client NetworkFunctionVendorSkusClient) ListByVendorSender(req *http.Request) (*http.Response, error) {
241	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
242}
243
244// ListByVendorResponder handles the response to the ListByVendor request. The method always
245// closes the http.Response Body.
246func (client NetworkFunctionVendorSkusClient) ListByVendorResponder(resp *http.Response) (result NetworkFunctionSkuListResult, err error) {
247	err = autorest.Respond(
248		resp,
249		azure.WithErrorUnlessStatusCode(http.StatusOK),
250		autorest.ByUnmarshallingJSON(&result),
251		autorest.ByClosing())
252	result.Response = autorest.Response{Response: resp}
253	return
254}
255
256// listByVendorNextResults retrieves the next set of results, if any.
257func (client NetworkFunctionVendorSkusClient) listByVendorNextResults(ctx context.Context, lastResults NetworkFunctionSkuListResult) (result NetworkFunctionSkuListResult, err error) {
258	req, err := lastResults.networkFunctionSkuListResultPreparer(ctx)
259	if err != nil {
260		return result, autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "listByVendorNextResults", nil, "Failure preparing next results request")
261	}
262	if req == nil {
263		return
264	}
265	resp, err := client.ListByVendorSender(req)
266	if err != nil {
267		result.Response = autorest.Response{Response: resp}
268		return result, autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "listByVendorNextResults", resp, "Failure sending next results request")
269	}
270	result, err = client.ListByVendorResponder(resp)
271	if err != nil {
272		err = autorest.NewErrorWithError(err, "hybridnetwork.NetworkFunctionVendorSkusClient", "listByVendorNextResults", resp, "Failure responding to next results request")
273	}
274	return
275}
276
277// ListByVendorComplete enumerates all values, automatically crossing page boundaries as required.
278func (client NetworkFunctionVendorSkusClient) ListByVendorComplete(ctx context.Context, vendorName string) (result NetworkFunctionSkuListResultIterator, err error) {
279	if tracing.IsEnabled() {
280		ctx = tracing.StartSpan(ctx, fqdn+"/NetworkFunctionVendorSkusClient.ListByVendor")
281		defer func() {
282			sc := -1
283			if result.Response().Response.Response != nil {
284				sc = result.page.Response().Response.Response.StatusCode
285			}
286			tracing.EndSpan(ctx, sc, err)
287		}()
288	}
289	result.page, err = client.ListByVendor(ctx, vendorName)
290	return
291}
292