1package mariadb
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// LocationBasedRecommendedActionSessionsResultClient is the the Microsoft Azure management API provides create, read,
30// update, and delete functionality for Azure MariaDB resources including servers, databases, firewall rules, VNET
31// rules, log files and configurations with new business model.
32type LocationBasedRecommendedActionSessionsResultClient struct {
33	BaseClient
34}
35
36// NewLocationBasedRecommendedActionSessionsResultClient creates an instance of the
37// LocationBasedRecommendedActionSessionsResultClient client.
38func NewLocationBasedRecommendedActionSessionsResultClient(subscriptionID string) LocationBasedRecommendedActionSessionsResultClient {
39	return NewLocationBasedRecommendedActionSessionsResultClientWithBaseURI(DefaultBaseURI, subscriptionID)
40}
41
42// NewLocationBasedRecommendedActionSessionsResultClientWithBaseURI creates an instance of the
43// LocationBasedRecommendedActionSessionsResultClient client using a custom endpoint.  Use this when interacting with
44// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
45func NewLocationBasedRecommendedActionSessionsResultClientWithBaseURI(baseURI string, subscriptionID string) LocationBasedRecommendedActionSessionsResultClient {
46	return LocationBasedRecommendedActionSessionsResultClient{NewWithBaseURI(baseURI, subscriptionID)}
47}
48
49// List recommendation action session operation result.
50// Parameters:
51// locationName - the name of the location.
52// operationID - the operation identifier.
53func (client LocationBasedRecommendedActionSessionsResultClient) List(ctx context.Context, locationName string, operationID string) (result RecommendationActionsResultListPage, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/LocationBasedRecommendedActionSessionsResultClient.List")
56		defer func() {
57			sc := -1
58			if result.rarl.Response.Response != nil {
59				sc = result.rarl.Response.Response.StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	if err := validation.Validate([]validation.Validation{
65		{TargetValue: client.SubscriptionID,
66			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
67		return result, validation.NewError("mariadb.LocationBasedRecommendedActionSessionsResultClient", "List", err.Error())
68	}
69
70	result.fn = client.listNextResults
71	req, err := client.ListPreparer(ctx, locationName, operationID)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "List", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.ListSender(req)
78	if err != nil {
79		result.rarl.Response = autorest.Response{Response: resp}
80		err = autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "List", resp, "Failure sending request")
81		return
82	}
83
84	result.rarl, err = client.ListResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "List", resp, "Failure responding to request")
87		return
88	}
89	if result.rarl.hasNextLink() && result.rarl.IsEmpty() {
90		err = result.NextWithContext(ctx)
91		return
92	}
93
94	return
95}
96
97// ListPreparer prepares the List request.
98func (client LocationBasedRecommendedActionSessionsResultClient) ListPreparer(ctx context.Context, locationName string, operationID string) (*http.Request, error) {
99	pathParameters := map[string]interface{}{
100		"locationName":   autorest.Encode("path", locationName),
101		"operationId":    autorest.Encode("path", operationID),
102		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
103	}
104
105	const APIVersion = "2018-06-01"
106	queryParameters := map[string]interface{}{
107		"api-version": APIVersion,
108	}
109
110	preparer := autorest.CreatePreparer(
111		autorest.AsGet(),
112		autorest.WithBaseURL(client.BaseURI),
113		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBforMariaDB/locations/{locationName}/recommendedActionSessionsOperationResults/{operationId}", pathParameters),
114		autorest.WithQueryParameters(queryParameters))
115	return preparer.Prepare((&http.Request{}).WithContext(ctx))
116}
117
118// ListSender sends the List request. The method will close the
119// http.Response Body if it receives an error.
120func (client LocationBasedRecommendedActionSessionsResultClient) ListSender(req *http.Request) (*http.Response, error) {
121	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
122}
123
124// ListResponder handles the response to the List request. The method always
125// closes the http.Response Body.
126func (client LocationBasedRecommendedActionSessionsResultClient) ListResponder(resp *http.Response) (result RecommendationActionsResultList, err error) {
127	err = autorest.Respond(
128		resp,
129		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
130		autorest.ByUnmarshallingJSON(&result),
131		autorest.ByClosing())
132	result.Response = autorest.Response{Response: resp}
133	return
134}
135
136// listNextResults retrieves the next set of results, if any.
137func (client LocationBasedRecommendedActionSessionsResultClient) listNextResults(ctx context.Context, lastResults RecommendationActionsResultList) (result RecommendationActionsResultList, err error) {
138	req, err := lastResults.recommendationActionsResultListPreparer(ctx)
139	if err != nil {
140		return result, autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "listNextResults", nil, "Failure preparing next results request")
141	}
142	if req == nil {
143		return
144	}
145	resp, err := client.ListSender(req)
146	if err != nil {
147		result.Response = autorest.Response{Response: resp}
148		return result, autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "listNextResults", resp, "Failure sending next results request")
149	}
150	result, err = client.ListResponder(resp)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "listNextResults", resp, "Failure responding to next results request")
153	}
154	return
155}
156
157// ListComplete enumerates all values, automatically crossing page boundaries as required.
158func (client LocationBasedRecommendedActionSessionsResultClient) ListComplete(ctx context.Context, locationName string, operationID string) (result RecommendationActionsResultListIterator, err error) {
159	if tracing.IsEnabled() {
160		ctx = tracing.StartSpan(ctx, fqdn+"/LocationBasedRecommendedActionSessionsResultClient.List")
161		defer func() {
162			sc := -1
163			if result.Response().Response.Response != nil {
164				sc = result.page.Response().Response.Response.StatusCode
165			}
166			tracing.EndSpan(ctx, sc, err)
167		}()
168	}
169	result.page, err = client.List(ctx, locationName, operationID)
170	return
171}
172