1package support
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/tracing"
25	"net/http"
26)
27
28// ProblemClassificationsClient is the microsoft Azure Support Resource Provider.
29type ProblemClassificationsClient struct {
30	BaseClient
31}
32
33// NewProblemClassificationsClient creates an instance of the ProblemClassificationsClient client.
34func NewProblemClassificationsClient(subscriptionID string) ProblemClassificationsClient {
35	return NewProblemClassificationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewProblemClassificationsClientWithBaseURI creates an instance of the ProblemClassificationsClient client using a
39// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
40// Azure stack).
41func NewProblemClassificationsClientWithBaseURI(baseURI string, subscriptionID string) ProblemClassificationsClient {
42	return ProblemClassificationsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Get gets the details of a specific problem classification for a specific Azure service.
46// Parameters:
47// serviceName - name of Azure service available for support.
48// problemClassificationName - name of problem classification.
49func (client ProblemClassificationsClient) Get(ctx context.Context, serviceName string, problemClassificationName string) (result ProblemClassification, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/ProblemClassificationsClient.Get")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	req, err := client.GetPreparer(ctx, serviceName, problemClassificationName)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "support.ProblemClassificationsClient", "Get", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.GetSender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "support.ProblemClassificationsClient", "Get", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.GetResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "support.ProblemClassificationsClient", "Get", resp, "Failure responding to request")
76		return
77	}
78
79	return
80}
81
82// GetPreparer prepares the Get request.
83func (client ProblemClassificationsClient) GetPreparer(ctx context.Context, serviceName string, problemClassificationName string) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"problemClassificationName": autorest.Encode("path", problemClassificationName),
86		"serviceName":               autorest.Encode("path", serviceName),
87	}
88
89	const APIVersion = "2019-05-01-preview"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	preparer := autorest.CreatePreparer(
95		autorest.AsGet(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/providers/Microsoft.Support/services/{serviceName}/problemClassifications/{problemClassificationName}", pathParameters),
98		autorest.WithQueryParameters(queryParameters))
99	return preparer.Prepare((&http.Request{}).WithContext(ctx))
100}
101
102// GetSender sends the Get request. The method will close the
103// http.Response Body if it receives an error.
104func (client ProblemClassificationsClient) GetSender(req *http.Request) (*http.Response, error) {
105	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
106}
107
108// GetResponder handles the response to the Get request. The method always
109// closes the http.Response Body.
110func (client ProblemClassificationsClient) GetResponder(resp *http.Response) (result ProblemClassification, err error) {
111	err = autorest.Respond(
112		resp,
113		azure.WithErrorUnlessStatusCode(http.StatusOK),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119
120// List lists all the problem classifications (categories) available for a specific Azure service.<br/><br/> Always use
121// the service and problem classifications obtained programmatically. This practice ensures that you always have the
122// most recent set of service and problem classification Ids.
123// Parameters:
124// serviceName - name of Azure service for which the problem classifications need to be retrieved.
125func (client ProblemClassificationsClient) List(ctx context.Context, serviceName string) (result ProblemClassificationsListResult, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/ProblemClassificationsClient.List")
128		defer func() {
129			sc := -1
130			if result.Response.Response != nil {
131				sc = result.Response.Response.StatusCode
132			}
133			tracing.EndSpan(ctx, sc, err)
134		}()
135	}
136	req, err := client.ListPreparer(ctx, serviceName)
137	if err != nil {
138		err = autorest.NewErrorWithError(err, "support.ProblemClassificationsClient", "List", nil, "Failure preparing request")
139		return
140	}
141
142	resp, err := client.ListSender(req)
143	if err != nil {
144		result.Response = autorest.Response{Response: resp}
145		err = autorest.NewErrorWithError(err, "support.ProblemClassificationsClient", "List", resp, "Failure sending request")
146		return
147	}
148
149	result, err = client.ListResponder(resp)
150	if err != nil {
151		err = autorest.NewErrorWithError(err, "support.ProblemClassificationsClient", "List", resp, "Failure responding to request")
152		return
153	}
154
155	return
156}
157
158// ListPreparer prepares the List request.
159func (client ProblemClassificationsClient) ListPreparer(ctx context.Context, serviceName string) (*http.Request, error) {
160	pathParameters := map[string]interface{}{
161		"serviceName": autorest.Encode("path", serviceName),
162	}
163
164	const APIVersion = "2019-05-01-preview"
165	queryParameters := map[string]interface{}{
166		"api-version": APIVersion,
167	}
168
169	preparer := autorest.CreatePreparer(
170		autorest.AsGet(),
171		autorest.WithBaseURL(client.BaseURI),
172		autorest.WithPathParameters("/providers/Microsoft.Support/services/{serviceName}/problemClassifications", pathParameters),
173		autorest.WithQueryParameters(queryParameters))
174	return preparer.Prepare((&http.Request{}).WithContext(ctx))
175}
176
177// ListSender sends the List request. The method will close the
178// http.Response Body if it receives an error.
179func (client ProblemClassificationsClient) ListSender(req *http.Request) (*http.Response, error) {
180	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
181}
182
183// ListResponder handles the response to the List request. The method always
184// closes the http.Response Body.
185func (client ProblemClassificationsClient) ListResponder(resp *http.Response) (result ProblemClassificationsListResult, err error) {
186	err = autorest.Respond(
187		resp,
188		azure.WithErrorUnlessStatusCode(http.StatusOK),
189		autorest.ByUnmarshallingJSON(&result),
190		autorest.ByClosing())
191	result.Response = autorest.Response{Response: resp}
192	return
193}
194