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	}
88
89	return
90}
91
92// ListPreparer prepares the List request.
93func (client LocationBasedRecommendedActionSessionsResultClient) ListPreparer(ctx context.Context, locationName string, operationID string) (*http.Request, error) {
94	pathParameters := map[string]interface{}{
95		"locationName":   autorest.Encode("path", locationName),
96		"operationId":    autorest.Encode("path", operationID),
97		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
98	}
99
100	const APIVersion = "2018-06-01"
101	queryParameters := map[string]interface{}{
102		"api-version": APIVersion,
103	}
104
105	preparer := autorest.CreatePreparer(
106		autorest.AsGet(),
107		autorest.WithBaseURL(client.BaseURI),
108		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBforMariaDB/locations/{locationName}/recommendedActionSessionsOperationResults/{operationId}", pathParameters),
109		autorest.WithQueryParameters(queryParameters))
110	return preparer.Prepare((&http.Request{}).WithContext(ctx))
111}
112
113// ListSender sends the List request. The method will close the
114// http.Response Body if it receives an error.
115func (client LocationBasedRecommendedActionSessionsResultClient) ListSender(req *http.Request) (*http.Response, error) {
116	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
117}
118
119// ListResponder handles the response to the List request. The method always
120// closes the http.Response Body.
121func (client LocationBasedRecommendedActionSessionsResultClient) ListResponder(resp *http.Response) (result RecommendationActionsResultList, err error) {
122	err = autorest.Respond(
123		resp,
124		client.ByInspecting(),
125		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
126		autorest.ByUnmarshallingJSON(&result),
127		autorest.ByClosing())
128	result.Response = autorest.Response{Response: resp}
129	return
130}
131
132// listNextResults retrieves the next set of results, if any.
133func (client LocationBasedRecommendedActionSessionsResultClient) listNextResults(ctx context.Context, lastResults RecommendationActionsResultList) (result RecommendationActionsResultList, err error) {
134	req, err := lastResults.recommendationActionsResultListPreparer(ctx)
135	if err != nil {
136		return result, autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "listNextResults", nil, "Failure preparing next results request")
137	}
138	if req == nil {
139		return
140	}
141	resp, err := client.ListSender(req)
142	if err != nil {
143		result.Response = autorest.Response{Response: resp}
144		return result, autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "listNextResults", resp, "Failure sending next results request")
145	}
146	result, err = client.ListResponder(resp)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "mariadb.LocationBasedRecommendedActionSessionsResultClient", "listNextResults", resp, "Failure responding to next results request")
149	}
150	return
151}
152
153// ListComplete enumerates all values, automatically crossing page boundaries as required.
154func (client LocationBasedRecommendedActionSessionsResultClient) ListComplete(ctx context.Context, locationName string, operationID string) (result RecommendationActionsResultListIterator, err error) {
155	if tracing.IsEnabled() {
156		ctx = tracing.StartSpan(ctx, fqdn+"/LocationBasedRecommendedActionSessionsResultClient.List")
157		defer func() {
158			sc := -1
159			if result.Response().Response.Response != nil {
160				sc = result.page.Response().Response.Response.StatusCode
161			}
162			tracing.EndSpan(ctx, sc, err)
163		}()
164	}
165	result.page, err = client.List(ctx, locationName, operationID)
166	return
167}
168