1package apimanagement
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// EmailTemplateClient is the apiManagement Client
30type EmailTemplateClient struct {
31	BaseClient
32}
33
34// NewEmailTemplateClient creates an instance of the EmailTemplateClient client.
35func NewEmailTemplateClient(subscriptionID string) EmailTemplateClient {
36	return NewEmailTemplateClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewEmailTemplateClientWithBaseURI creates an instance of the EmailTemplateClient client using a custom endpoint.
40// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewEmailTemplateClientWithBaseURI(baseURI string, subscriptionID string) EmailTemplateClient {
42	return EmailTemplateClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CreateOrUpdate updates an Email Template.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// serviceName - the name of the API Management service.
49// templateName - email Template Name Identifier.
50// parameters - email Template update parameters.
51// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
52func (client EmailTemplateClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName, parameters EmailTemplateUpdateParameters, ifMatch string) (result EmailTemplateContract, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/EmailTemplateClient.CreateOrUpdate")
55		defer func() {
56			sc := -1
57			if result.Response.Response != nil {
58				sc = result.Response.Response.StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: serviceName,
65			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
66				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
67				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
68		{TargetValue: parameters,
69			Constraints: []validation.Constraint{{Target: "parameters.EmailTemplateUpdateParameterProperties", Name: validation.Null, Rule: false,
70				Chain: []validation.Constraint{{Target: "parameters.EmailTemplateUpdateParameterProperties.Subject", Name: validation.Null, Rule: false,
71					Chain: []validation.Constraint{{Target: "parameters.EmailTemplateUpdateParameterProperties.Subject", Name: validation.MaxLength, Rule: 1000, Chain: nil},
72						{Target: "parameters.EmailTemplateUpdateParameterProperties.Subject", Name: validation.MinLength, Rule: 1, Chain: nil},
73					}},
74					{Target: "parameters.EmailTemplateUpdateParameterProperties.Body", Name: validation.Null, Rule: false,
75						Chain: []validation.Constraint{{Target: "parameters.EmailTemplateUpdateParameterProperties.Body", Name: validation.MinLength, Rule: 1, Chain: nil}}},
76				}}}}}); err != nil {
77		return result, validation.NewError("apimanagement.EmailTemplateClient", "CreateOrUpdate", err.Error())
78	}
79
80	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, templateName, parameters, ifMatch)
81	if err != nil {
82		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "CreateOrUpdate", nil, "Failure preparing request")
83		return
84	}
85
86	resp, err := client.CreateOrUpdateSender(req)
87	if err != nil {
88		result.Response = autorest.Response{Response: resp}
89		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "CreateOrUpdate", resp, "Failure sending request")
90		return
91	}
92
93	result, err = client.CreateOrUpdateResponder(resp)
94	if err != nil {
95		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "CreateOrUpdate", resp, "Failure responding to request")
96		return
97	}
98
99	return
100}
101
102// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
103func (client EmailTemplateClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName, parameters EmailTemplateUpdateParameters, ifMatch string) (*http.Request, error) {
104	pathParameters := map[string]interface{}{
105		"resourceGroupName": autorest.Encode("path", resourceGroupName),
106		"serviceName":       autorest.Encode("path", serviceName),
107		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
108		"templateName":      autorest.Encode("path", templateName),
109	}
110
111	const APIVersion = "2019-12-01"
112	queryParameters := map[string]interface{}{
113		"api-version": APIVersion,
114	}
115
116	preparer := autorest.CreatePreparer(
117		autorest.AsContentType("application/json; charset=utf-8"),
118		autorest.AsPut(),
119		autorest.WithBaseURL(client.BaseURI),
120		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/templates/{templateName}", pathParameters),
121		autorest.WithJSON(parameters),
122		autorest.WithQueryParameters(queryParameters))
123	if len(ifMatch) > 0 {
124		preparer = autorest.DecoratePreparer(preparer,
125			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
126	}
127	return preparer.Prepare((&http.Request{}).WithContext(ctx))
128}
129
130// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
131// http.Response Body if it receives an error.
132func (client EmailTemplateClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
133	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
134}
135
136// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
137// closes the http.Response Body.
138func (client EmailTemplateClient) CreateOrUpdateResponder(resp *http.Response) (result EmailTemplateContract, err error) {
139	err = autorest.Respond(
140		resp,
141		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
142		autorest.ByUnmarshallingJSON(&result),
143		autorest.ByClosing())
144	result.Response = autorest.Response{Response: resp}
145	return
146}
147
148// Delete reset the Email Template to default template provided by the API Management service instance.
149// Parameters:
150// resourceGroupName - the name of the resource group.
151// serviceName - the name of the API Management service.
152// templateName - email Template Name Identifier.
153// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
154// request or it should be * for unconditional update.
155func (client EmailTemplateClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName, ifMatch string) (result autorest.Response, err error) {
156	if tracing.IsEnabled() {
157		ctx = tracing.StartSpan(ctx, fqdn+"/EmailTemplateClient.Delete")
158		defer func() {
159			sc := -1
160			if result.Response != nil {
161				sc = result.Response.StatusCode
162			}
163			tracing.EndSpan(ctx, sc, err)
164		}()
165	}
166	if err := validation.Validate([]validation.Validation{
167		{TargetValue: serviceName,
168			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
169				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
170				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
171		return result, validation.NewError("apimanagement.EmailTemplateClient", "Delete", err.Error())
172	}
173
174	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, templateName, ifMatch)
175	if err != nil {
176		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Delete", nil, "Failure preparing request")
177		return
178	}
179
180	resp, err := client.DeleteSender(req)
181	if err != nil {
182		result.Response = resp
183		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Delete", resp, "Failure sending request")
184		return
185	}
186
187	result, err = client.DeleteResponder(resp)
188	if err != nil {
189		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Delete", resp, "Failure responding to request")
190		return
191	}
192
193	return
194}
195
196// DeletePreparer prepares the Delete request.
197func (client EmailTemplateClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName, ifMatch string) (*http.Request, error) {
198	pathParameters := map[string]interface{}{
199		"resourceGroupName": autorest.Encode("path", resourceGroupName),
200		"serviceName":       autorest.Encode("path", serviceName),
201		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
202		"templateName":      autorest.Encode("path", templateName),
203	}
204
205	const APIVersion = "2019-12-01"
206	queryParameters := map[string]interface{}{
207		"api-version": APIVersion,
208	}
209
210	preparer := autorest.CreatePreparer(
211		autorest.AsDelete(),
212		autorest.WithBaseURL(client.BaseURI),
213		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/templates/{templateName}", pathParameters),
214		autorest.WithQueryParameters(queryParameters),
215		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
216	return preparer.Prepare((&http.Request{}).WithContext(ctx))
217}
218
219// DeleteSender sends the Delete request. The method will close the
220// http.Response Body if it receives an error.
221func (client EmailTemplateClient) DeleteSender(req *http.Request) (*http.Response, error) {
222	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
223}
224
225// DeleteResponder handles the response to the Delete request. The method always
226// closes the http.Response Body.
227func (client EmailTemplateClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
228	err = autorest.Respond(
229		resp,
230		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
231		autorest.ByClosing())
232	result.Response = resp
233	return
234}
235
236// Get gets the details of the email template specified by its identifier.
237// Parameters:
238// resourceGroupName - the name of the resource group.
239// serviceName - the name of the API Management service.
240// templateName - email Template Name Identifier.
241func (client EmailTemplateClient) Get(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName) (result EmailTemplateContract, err error) {
242	if tracing.IsEnabled() {
243		ctx = tracing.StartSpan(ctx, fqdn+"/EmailTemplateClient.Get")
244		defer func() {
245			sc := -1
246			if result.Response.Response != nil {
247				sc = result.Response.Response.StatusCode
248			}
249			tracing.EndSpan(ctx, sc, err)
250		}()
251	}
252	if err := validation.Validate([]validation.Validation{
253		{TargetValue: serviceName,
254			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
255				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
256				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
257		return result, validation.NewError("apimanagement.EmailTemplateClient", "Get", err.Error())
258	}
259
260	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, templateName)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Get", nil, "Failure preparing request")
263		return
264	}
265
266	resp, err := client.GetSender(req)
267	if err != nil {
268		result.Response = autorest.Response{Response: resp}
269		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Get", resp, "Failure sending request")
270		return
271	}
272
273	result, err = client.GetResponder(resp)
274	if err != nil {
275		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Get", resp, "Failure responding to request")
276		return
277	}
278
279	return
280}
281
282// GetPreparer prepares the Get request.
283func (client EmailTemplateClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName) (*http.Request, error) {
284	pathParameters := map[string]interface{}{
285		"resourceGroupName": autorest.Encode("path", resourceGroupName),
286		"serviceName":       autorest.Encode("path", serviceName),
287		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
288		"templateName":      autorest.Encode("path", templateName),
289	}
290
291	const APIVersion = "2019-12-01"
292	queryParameters := map[string]interface{}{
293		"api-version": APIVersion,
294	}
295
296	preparer := autorest.CreatePreparer(
297		autorest.AsGet(),
298		autorest.WithBaseURL(client.BaseURI),
299		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/templates/{templateName}", pathParameters),
300		autorest.WithQueryParameters(queryParameters))
301	return preparer.Prepare((&http.Request{}).WithContext(ctx))
302}
303
304// GetSender sends the Get request. The method will close the
305// http.Response Body if it receives an error.
306func (client EmailTemplateClient) GetSender(req *http.Request) (*http.Response, error) {
307	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
308}
309
310// GetResponder handles the response to the Get request. The method always
311// closes the http.Response Body.
312func (client EmailTemplateClient) GetResponder(resp *http.Response) (result EmailTemplateContract, err error) {
313	err = autorest.Respond(
314		resp,
315		azure.WithErrorUnlessStatusCode(http.StatusOK),
316		autorest.ByUnmarshallingJSON(&result),
317		autorest.ByClosing())
318	result.Response = autorest.Response{Response: resp}
319	return
320}
321
322// GetEntityTag gets the entity state (Etag) version of the email template specified by its identifier.
323// Parameters:
324// resourceGroupName - the name of the resource group.
325// serviceName - the name of the API Management service.
326// templateName - email Template Name Identifier.
327func (client EmailTemplateClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName) (result autorest.Response, err error) {
328	if tracing.IsEnabled() {
329		ctx = tracing.StartSpan(ctx, fqdn+"/EmailTemplateClient.GetEntityTag")
330		defer func() {
331			sc := -1
332			if result.Response != nil {
333				sc = result.Response.StatusCode
334			}
335			tracing.EndSpan(ctx, sc, err)
336		}()
337	}
338	if err := validation.Validate([]validation.Validation{
339		{TargetValue: serviceName,
340			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
341				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
342				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
343		return result, validation.NewError("apimanagement.EmailTemplateClient", "GetEntityTag", err.Error())
344	}
345
346	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, templateName)
347	if err != nil {
348		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "GetEntityTag", nil, "Failure preparing request")
349		return
350	}
351
352	resp, err := client.GetEntityTagSender(req)
353	if err != nil {
354		result.Response = resp
355		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "GetEntityTag", resp, "Failure sending request")
356		return
357	}
358
359	result, err = client.GetEntityTagResponder(resp)
360	if err != nil {
361		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "GetEntityTag", resp, "Failure responding to request")
362		return
363	}
364
365	return
366}
367
368// GetEntityTagPreparer prepares the GetEntityTag request.
369func (client EmailTemplateClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName) (*http.Request, error) {
370	pathParameters := map[string]interface{}{
371		"resourceGroupName": autorest.Encode("path", resourceGroupName),
372		"serviceName":       autorest.Encode("path", serviceName),
373		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
374		"templateName":      autorest.Encode("path", templateName),
375	}
376
377	const APIVersion = "2019-12-01"
378	queryParameters := map[string]interface{}{
379		"api-version": APIVersion,
380	}
381
382	preparer := autorest.CreatePreparer(
383		autorest.AsHead(),
384		autorest.WithBaseURL(client.BaseURI),
385		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/templates/{templateName}", pathParameters),
386		autorest.WithQueryParameters(queryParameters))
387	return preparer.Prepare((&http.Request{}).WithContext(ctx))
388}
389
390// GetEntityTagSender sends the GetEntityTag request. The method will close the
391// http.Response Body if it receives an error.
392func (client EmailTemplateClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
393	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
394}
395
396// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
397// closes the http.Response Body.
398func (client EmailTemplateClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
399	err = autorest.Respond(
400		resp,
401		azure.WithErrorUnlessStatusCode(http.StatusOK),
402		autorest.ByClosing())
403	result.Response = resp
404	return
405}
406
407// ListByService lists a collection of properties defined within a service instance.
408// Parameters:
409// resourceGroupName - the name of the resource group.
410// serviceName - the name of the API Management service.
411// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
412// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
413// | substringof, contains, startswith, endswith | </br>
414// top - number of records to return.
415// skip - number of records to skip.
416func (client EmailTemplateClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result EmailTemplateCollectionPage, err error) {
417	if tracing.IsEnabled() {
418		ctx = tracing.StartSpan(ctx, fqdn+"/EmailTemplateClient.ListByService")
419		defer func() {
420			sc := -1
421			if result.etc.Response.Response != nil {
422				sc = result.etc.Response.Response.StatusCode
423			}
424			tracing.EndSpan(ctx, sc, err)
425		}()
426	}
427	if err := validation.Validate([]validation.Validation{
428		{TargetValue: serviceName,
429			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
430				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
431				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
432		{TargetValue: top,
433			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
434				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
435		{TargetValue: skip,
436			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
437				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
438		return result, validation.NewError("apimanagement.EmailTemplateClient", "ListByService", err.Error())
439	}
440
441	result.fn = client.listByServiceNextResults
442	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
443	if err != nil {
444		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "ListByService", nil, "Failure preparing request")
445		return
446	}
447
448	resp, err := client.ListByServiceSender(req)
449	if err != nil {
450		result.etc.Response = autorest.Response{Response: resp}
451		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "ListByService", resp, "Failure sending request")
452		return
453	}
454
455	result.etc, err = client.ListByServiceResponder(resp)
456	if err != nil {
457		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "ListByService", resp, "Failure responding to request")
458		return
459	}
460	if result.etc.hasNextLink() && result.etc.IsEmpty() {
461		err = result.NextWithContext(ctx)
462		return
463	}
464
465	return
466}
467
468// ListByServicePreparer prepares the ListByService request.
469func (client EmailTemplateClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
470	pathParameters := map[string]interface{}{
471		"resourceGroupName": autorest.Encode("path", resourceGroupName),
472		"serviceName":       autorest.Encode("path", serviceName),
473		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
474	}
475
476	const APIVersion = "2019-12-01"
477	queryParameters := map[string]interface{}{
478		"api-version": APIVersion,
479	}
480	if len(filter) > 0 {
481		queryParameters["$filter"] = autorest.Encode("query", filter)
482	}
483	if top != nil {
484		queryParameters["$top"] = autorest.Encode("query", *top)
485	}
486	if skip != nil {
487		queryParameters["$skip"] = autorest.Encode("query", *skip)
488	}
489
490	preparer := autorest.CreatePreparer(
491		autorest.AsGet(),
492		autorest.WithBaseURL(client.BaseURI),
493		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/templates", pathParameters),
494		autorest.WithQueryParameters(queryParameters))
495	return preparer.Prepare((&http.Request{}).WithContext(ctx))
496}
497
498// ListByServiceSender sends the ListByService request. The method will close the
499// http.Response Body if it receives an error.
500func (client EmailTemplateClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
501	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
502}
503
504// ListByServiceResponder handles the response to the ListByService request. The method always
505// closes the http.Response Body.
506func (client EmailTemplateClient) ListByServiceResponder(resp *http.Response) (result EmailTemplateCollection, err error) {
507	err = autorest.Respond(
508		resp,
509		azure.WithErrorUnlessStatusCode(http.StatusOK),
510		autorest.ByUnmarshallingJSON(&result),
511		autorest.ByClosing())
512	result.Response = autorest.Response{Response: resp}
513	return
514}
515
516// listByServiceNextResults retrieves the next set of results, if any.
517func (client EmailTemplateClient) listByServiceNextResults(ctx context.Context, lastResults EmailTemplateCollection) (result EmailTemplateCollection, err error) {
518	req, err := lastResults.emailTemplateCollectionPreparer(ctx)
519	if err != nil {
520		return result, autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "listByServiceNextResults", nil, "Failure preparing next results request")
521	}
522	if req == nil {
523		return
524	}
525	resp, err := client.ListByServiceSender(req)
526	if err != nil {
527		result.Response = autorest.Response{Response: resp}
528		return result, autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "listByServiceNextResults", resp, "Failure sending next results request")
529	}
530	result, err = client.ListByServiceResponder(resp)
531	if err != nil {
532		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "listByServiceNextResults", resp, "Failure responding to next results request")
533	}
534	return
535}
536
537// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
538func (client EmailTemplateClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result EmailTemplateCollectionIterator, err error) {
539	if tracing.IsEnabled() {
540		ctx = tracing.StartSpan(ctx, fqdn+"/EmailTemplateClient.ListByService")
541		defer func() {
542			sc := -1
543			if result.Response().Response.Response != nil {
544				sc = result.page.Response().Response.Response.StatusCode
545			}
546			tracing.EndSpan(ctx, sc, err)
547		}()
548	}
549	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
550	return
551}
552
553// Update updates the specific Email Template.
554// Parameters:
555// resourceGroupName - the name of the resource group.
556// serviceName - the name of the API Management service.
557// templateName - email Template Name Identifier.
558// parameters - update parameters.
559// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
560// request or it should be * for unconditional update.
561func (client EmailTemplateClient) Update(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName, parameters EmailTemplateUpdateParameters, ifMatch string) (result autorest.Response, err error) {
562	if tracing.IsEnabled() {
563		ctx = tracing.StartSpan(ctx, fqdn+"/EmailTemplateClient.Update")
564		defer func() {
565			sc := -1
566			if result.Response != nil {
567				sc = result.Response.StatusCode
568			}
569			tracing.EndSpan(ctx, sc, err)
570		}()
571	}
572	if err := validation.Validate([]validation.Validation{
573		{TargetValue: serviceName,
574			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
575				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
576				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil {
577		return result, validation.NewError("apimanagement.EmailTemplateClient", "Update", err.Error())
578	}
579
580	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, templateName, parameters, ifMatch)
581	if err != nil {
582		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Update", nil, "Failure preparing request")
583		return
584	}
585
586	resp, err := client.UpdateSender(req)
587	if err != nil {
588		result.Response = resp
589		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Update", resp, "Failure sending request")
590		return
591	}
592
593	result, err = client.UpdateResponder(resp)
594	if err != nil {
595		err = autorest.NewErrorWithError(err, "apimanagement.EmailTemplateClient", "Update", resp, "Failure responding to request")
596		return
597	}
598
599	return
600}
601
602// UpdatePreparer prepares the Update request.
603func (client EmailTemplateClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, templateName TemplateName, parameters EmailTemplateUpdateParameters, ifMatch string) (*http.Request, error) {
604	pathParameters := map[string]interface{}{
605		"resourceGroupName": autorest.Encode("path", resourceGroupName),
606		"serviceName":       autorest.Encode("path", serviceName),
607		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
608		"templateName":      autorest.Encode("path", templateName),
609	}
610
611	const APIVersion = "2019-12-01"
612	queryParameters := map[string]interface{}{
613		"api-version": APIVersion,
614	}
615
616	preparer := autorest.CreatePreparer(
617		autorest.AsContentType("application/json; charset=utf-8"),
618		autorest.AsPatch(),
619		autorest.WithBaseURL(client.BaseURI),
620		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/templates/{templateName}", pathParameters),
621		autorest.WithJSON(parameters),
622		autorest.WithQueryParameters(queryParameters),
623		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
624	return preparer.Prepare((&http.Request{}).WithContext(ctx))
625}
626
627// UpdateSender sends the Update request. The method will close the
628// http.Response Body if it receives an error.
629func (client EmailTemplateClient) UpdateSender(req *http.Request) (*http.Response, error) {
630	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
631}
632
633// UpdateResponder handles the response to the Update request. The method always
634// closes the http.Response Body.
635func (client EmailTemplateClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
636	err = autorest.Respond(
637		resp,
638		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
639		autorest.ByClosing())
640	result.Response = resp
641	return
642}
643