1package apimanagement
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// NotificationRecipientUserClient is the apiManagement Client
19type NotificationRecipientUserClient struct {
20	BaseClient
21}
22
23// NewNotificationRecipientUserClient creates an instance of the NotificationRecipientUserClient client.
24func NewNotificationRecipientUserClient(subscriptionID string) NotificationRecipientUserClient {
25	return NewNotificationRecipientUserClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewNotificationRecipientUserClientWithBaseURI creates an instance of the NotificationRecipientUserClient client
29// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewNotificationRecipientUserClientWithBaseURI(baseURI string, subscriptionID string) NotificationRecipientUserClient {
32	return NotificationRecipientUserClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CheckEntityExists determine if the Notification Recipient User is subscribed to the notification.
36// Parameters:
37// resourceGroupName - the name of the resource group.
38// serviceName - the name of the API Management service.
39// notificationName - notification Name Identifier.
40// userID - user identifier. Must be unique in the current API Management service instance.
41func (client NotificationRecipientUserClient) CheckEntityExists(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, userID string) (result autorest.Response, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/NotificationRecipientUserClient.CheckEntityExists")
44		defer func() {
45			sc := -1
46			if result.Response != nil {
47				sc = result.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: serviceName,
54			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
55				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
57		{TargetValue: userID,
58			Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil},
59				{Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
60		return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "CheckEntityExists", err.Error())
61	}
62
63	req, err := client.CheckEntityExistsPreparer(ctx, resourceGroupName, serviceName, notificationName, userID)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CheckEntityExists", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.CheckEntityExistsSender(req)
70	if err != nil {
71		result.Response = resp
72		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CheckEntityExists", resp, "Failure sending request")
73		return
74	}
75
76	result, err = client.CheckEntityExistsResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CheckEntityExists", resp, "Failure responding to request")
79		return
80	}
81
82	return
83}
84
85// CheckEntityExistsPreparer prepares the CheckEntityExists request.
86func (client NotificationRecipientUserClient) CheckEntityExistsPreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, userID string) (*http.Request, error) {
87	pathParameters := map[string]interface{}{
88		"notificationName":  autorest.Encode("path", notificationName),
89		"resourceGroupName": autorest.Encode("path", resourceGroupName),
90		"serviceName":       autorest.Encode("path", serviceName),
91		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
92		"userId":            autorest.Encode("path", userID),
93	}
94
95	const APIVersion = "2020-12-01"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsHead(),
102		autorest.WithBaseURL(client.BaseURI),
103		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers/{userId}", pathParameters),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// CheckEntityExistsSender sends the CheckEntityExists request. The method will close the
109// http.Response Body if it receives an error.
110func (client NotificationRecipientUserClient) CheckEntityExistsSender(req *http.Request) (*http.Response, error) {
111	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
112}
113
114// CheckEntityExistsResponder handles the response to the CheckEntityExists request. The method always
115// closes the http.Response Body.
116func (client NotificationRecipientUserClient) CheckEntityExistsResponder(resp *http.Response) (result autorest.Response, err error) {
117	err = autorest.Respond(
118		resp,
119		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusNotFound),
120		autorest.ByClosing())
121	result.Response = resp
122	return
123}
124
125// CreateOrUpdate adds the API Management User to the list of Recipients for the Notification.
126// Parameters:
127// resourceGroupName - the name of the resource group.
128// serviceName - the name of the API Management service.
129// notificationName - notification Name Identifier.
130// userID - user identifier. Must be unique in the current API Management service instance.
131func (client NotificationRecipientUserClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, userID string) (result RecipientUserContract, err error) {
132	if tracing.IsEnabled() {
133		ctx = tracing.StartSpan(ctx, fqdn+"/NotificationRecipientUserClient.CreateOrUpdate")
134		defer func() {
135			sc := -1
136			if result.Response.Response != nil {
137				sc = result.Response.Response.StatusCode
138			}
139			tracing.EndSpan(ctx, sc, err)
140		}()
141	}
142	if err := validation.Validate([]validation.Validation{
143		{TargetValue: serviceName,
144			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
145				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
146				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
147		{TargetValue: userID,
148			Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil},
149				{Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
150		return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", err.Error())
151	}
152
153	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, notificationName, userID)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", nil, "Failure preparing request")
156		return
157	}
158
159	resp, err := client.CreateOrUpdateSender(req)
160	if err != nil {
161		result.Response = autorest.Response{Response: resp}
162		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", resp, "Failure sending request")
163		return
164	}
165
166	result, err = client.CreateOrUpdateResponder(resp)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "CreateOrUpdate", resp, "Failure responding to request")
169		return
170	}
171
172	return
173}
174
175// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
176func (client NotificationRecipientUserClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, userID string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"notificationName":  autorest.Encode("path", notificationName),
179		"resourceGroupName": autorest.Encode("path", resourceGroupName),
180		"serviceName":       autorest.Encode("path", serviceName),
181		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
182		"userId":            autorest.Encode("path", userID),
183	}
184
185	const APIVersion = "2020-12-01"
186	queryParameters := map[string]interface{}{
187		"api-version": APIVersion,
188	}
189
190	preparer := autorest.CreatePreparer(
191		autorest.AsPut(),
192		autorest.WithBaseURL(client.BaseURI),
193		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers/{userId}", pathParameters),
194		autorest.WithQueryParameters(queryParameters))
195	return preparer.Prepare((&http.Request{}).WithContext(ctx))
196}
197
198// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
199// http.Response Body if it receives an error.
200func (client NotificationRecipientUserClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
201	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
202}
203
204// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
205// closes the http.Response Body.
206func (client NotificationRecipientUserClient) CreateOrUpdateResponder(resp *http.Response) (result RecipientUserContract, err error) {
207	err = autorest.Respond(
208		resp,
209		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
210		autorest.ByUnmarshallingJSON(&result),
211		autorest.ByClosing())
212	result.Response = autorest.Response{Response: resp}
213	return
214}
215
216// Delete removes the API Management user from the list of Notification.
217// Parameters:
218// resourceGroupName - the name of the resource group.
219// serviceName - the name of the API Management service.
220// notificationName - notification Name Identifier.
221// userID - user identifier. Must be unique in the current API Management service instance.
222func (client NotificationRecipientUserClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, userID string) (result autorest.Response, err error) {
223	if tracing.IsEnabled() {
224		ctx = tracing.StartSpan(ctx, fqdn+"/NotificationRecipientUserClient.Delete")
225		defer func() {
226			sc := -1
227			if result.Response != nil {
228				sc = result.Response.StatusCode
229			}
230			tracing.EndSpan(ctx, sc, err)
231		}()
232	}
233	if err := validation.Validate([]validation.Validation{
234		{TargetValue: serviceName,
235			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
236				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
237				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
238		{TargetValue: userID,
239			Constraints: []validation.Constraint{{Target: "userID", Name: validation.MaxLength, Rule: 80, Chain: nil},
240				{Target: "userID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
241		return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "Delete", err.Error())
242	}
243
244	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, notificationName, userID)
245	if err != nil {
246		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", nil, "Failure preparing request")
247		return
248	}
249
250	resp, err := client.DeleteSender(req)
251	if err != nil {
252		result.Response = resp
253		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", resp, "Failure sending request")
254		return
255	}
256
257	result, err = client.DeleteResponder(resp)
258	if err != nil {
259		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "Delete", resp, "Failure responding to request")
260		return
261	}
262
263	return
264}
265
266// DeletePreparer prepares the Delete request.
267func (client NotificationRecipientUserClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName, userID string) (*http.Request, error) {
268	pathParameters := map[string]interface{}{
269		"notificationName":  autorest.Encode("path", notificationName),
270		"resourceGroupName": autorest.Encode("path", resourceGroupName),
271		"serviceName":       autorest.Encode("path", serviceName),
272		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
273		"userId":            autorest.Encode("path", userID),
274	}
275
276	const APIVersion = "2020-12-01"
277	queryParameters := map[string]interface{}{
278		"api-version": APIVersion,
279	}
280
281	preparer := autorest.CreatePreparer(
282		autorest.AsDelete(),
283		autorest.WithBaseURL(client.BaseURI),
284		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers/{userId}", pathParameters),
285		autorest.WithQueryParameters(queryParameters))
286	return preparer.Prepare((&http.Request{}).WithContext(ctx))
287}
288
289// DeleteSender sends the Delete request. The method will close the
290// http.Response Body if it receives an error.
291func (client NotificationRecipientUserClient) DeleteSender(req *http.Request) (*http.Response, error) {
292	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
293}
294
295// DeleteResponder handles the response to the Delete request. The method always
296// closes the http.Response Body.
297func (client NotificationRecipientUserClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
298	err = autorest.Respond(
299		resp,
300		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
301		autorest.ByClosing())
302	result.Response = resp
303	return
304}
305
306// ListByNotification gets the list of the Notification Recipient User subscribed to the notification.
307// Parameters:
308// resourceGroupName - the name of the resource group.
309// serviceName - the name of the API Management service.
310// notificationName - notification Name Identifier.
311func (client NotificationRecipientUserClient) ListByNotification(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (result RecipientUserCollection, err error) {
312	if tracing.IsEnabled() {
313		ctx = tracing.StartSpan(ctx, fqdn+"/NotificationRecipientUserClient.ListByNotification")
314		defer func() {
315			sc := -1
316			if result.Response.Response != nil {
317				sc = result.Response.Response.StatusCode
318			}
319			tracing.EndSpan(ctx, sc, err)
320		}()
321	}
322	if err := validation.Validate([]validation.Validation{
323		{TargetValue: serviceName,
324			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
325				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
326				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
327		return result, validation.NewError("apimanagement.NotificationRecipientUserClient", "ListByNotification", err.Error())
328	}
329
330	req, err := client.ListByNotificationPreparer(ctx, resourceGroupName, serviceName, notificationName)
331	if err != nil {
332		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "ListByNotification", nil, "Failure preparing request")
333		return
334	}
335
336	resp, err := client.ListByNotificationSender(req)
337	if err != nil {
338		result.Response = autorest.Response{Response: resp}
339		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "ListByNotification", resp, "Failure sending request")
340		return
341	}
342
343	result, err = client.ListByNotificationResponder(resp)
344	if err != nil {
345		err = autorest.NewErrorWithError(err, "apimanagement.NotificationRecipientUserClient", "ListByNotification", resp, "Failure responding to request")
346		return
347	}
348
349	return
350}
351
352// ListByNotificationPreparer prepares the ListByNotification request.
353func (client NotificationRecipientUserClient) ListByNotificationPreparer(ctx context.Context, resourceGroupName string, serviceName string, notificationName NotificationName) (*http.Request, error) {
354	pathParameters := map[string]interface{}{
355		"notificationName":  autorest.Encode("path", notificationName),
356		"resourceGroupName": autorest.Encode("path", resourceGroupName),
357		"serviceName":       autorest.Encode("path", serviceName),
358		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
359	}
360
361	const APIVersion = "2020-12-01"
362	queryParameters := map[string]interface{}{
363		"api-version": APIVersion,
364	}
365
366	preparer := autorest.CreatePreparer(
367		autorest.AsGet(),
368		autorest.WithBaseURL(client.BaseURI),
369		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/notifications/{notificationName}/recipientUsers", pathParameters),
370		autorest.WithQueryParameters(queryParameters))
371	return preparer.Prepare((&http.Request{}).WithContext(ctx))
372}
373
374// ListByNotificationSender sends the ListByNotification request. The method will close the
375// http.Response Body if it receives an error.
376func (client NotificationRecipientUserClient) ListByNotificationSender(req *http.Request) (*http.Response, error) {
377	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
378}
379
380// ListByNotificationResponder handles the response to the ListByNotification request. The method always
381// closes the http.Response Body.
382func (client NotificationRecipientUserClient) ListByNotificationResponder(resp *http.Response) (result RecipientUserCollection, err error) {
383	err = autorest.Respond(
384		resp,
385		azure.WithErrorUnlessStatusCode(http.StatusOK),
386		autorest.ByUnmarshallingJSON(&result),
387		autorest.ByClosing())
388	result.Response = autorest.Response{Response: resp}
389	return
390}
391