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