1package synapse
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// SQLPoolOperationResultsClient is the azure Synapse Analytics Management Client
19type SQLPoolOperationResultsClient struct {
20	BaseClient
21}
22
23// NewSQLPoolOperationResultsClient creates an instance of the SQLPoolOperationResultsClient client.
24func NewSQLPoolOperationResultsClient(subscriptionID string) SQLPoolOperationResultsClient {
25	return NewSQLPoolOperationResultsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewSQLPoolOperationResultsClientWithBaseURI creates an instance of the SQLPoolOperationResultsClient client using a
29// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
30// Azure stack).
31func NewSQLPoolOperationResultsClientWithBaseURI(baseURI string, subscriptionID string) SQLPoolOperationResultsClient {
32	return SQLPoolOperationResultsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// GetLocationHeaderResult get the status of a SQL pool operation
36// Parameters:
37// resourceGroupName - the name of the resource group. The name is case insensitive.
38// workspaceName - the name of the workspace
39// SQLPoolName - SQL pool name
40// operationID - operation ID
41func (client SQLPoolOperationResultsClient) GetLocationHeaderResult(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, operationID string) (result SetObject, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/SQLPoolOperationResultsClient.GetLocationHeaderResult")
44		defer func() {
45			sc := -1
46			if result.Response.Response != nil {
47				sc = result.Response.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: client.SubscriptionID,
54			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
55		{TargetValue: resourceGroupName,
56			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
57				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
58				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
59		return result, validation.NewError("synapse.SQLPoolOperationResultsClient", "GetLocationHeaderResult", err.Error())
60	}
61
62	req, err := client.GetLocationHeaderResultPreparer(ctx, resourceGroupName, workspaceName, SQLPoolName, operationID)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "synapse.SQLPoolOperationResultsClient", "GetLocationHeaderResult", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.GetLocationHeaderResultSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "synapse.SQLPoolOperationResultsClient", "GetLocationHeaderResult", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.GetLocationHeaderResultResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "synapse.SQLPoolOperationResultsClient", "GetLocationHeaderResult", resp, "Failure responding to request")
78		return
79	}
80
81	return
82}
83
84// GetLocationHeaderResultPreparer prepares the GetLocationHeaderResult request.
85func (client SQLPoolOperationResultsClient) GetLocationHeaderResultPreparer(ctx context.Context, resourceGroupName string, workspaceName string, SQLPoolName string, operationID string) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"operationId":       autorest.Encode("path", operationID),
88		"resourceGroupName": autorest.Encode("path", resourceGroupName),
89		"sqlPoolName":       autorest.Encode("path", SQLPoolName),
90		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
91		"workspaceName":     autorest.Encode("path", workspaceName),
92	}
93
94	const APIVersion = "2021-03-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}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/sqlPools/{sqlPoolName}/operationResults/{operationId}", pathParameters),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// GetLocationHeaderResultSender sends the GetLocationHeaderResult request. The method will close the
108// http.Response Body if it receives an error.
109func (client SQLPoolOperationResultsClient) GetLocationHeaderResultSender(req *http.Request) (*http.Response, error) {
110	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
111}
112
113// GetLocationHeaderResultResponder handles the response to the GetLocationHeaderResult request. The method always
114// closes the http.Response Body.
115func (client SQLPoolOperationResultsClient) GetLocationHeaderResultResponder(resp *http.Response) (result SetObject, err error) {
116	err = autorest.Respond(
117		resp,
118		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
119		autorest.ByUnmarshallingJSON(&result.Value),
120		autorest.ByClosing())
121	result.Response = autorest.Response{Response: resp}
122	return
123}
124