// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package armappservice

import (
	"context"
	"errors"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
	"net/http"
	"net/url"
	"strings"
)

// SiteCertificatesClient contains the methods for the SiteCertificates group.
// Don't use this type directly, use NewSiteCertificatesClient() instead.
type SiteCertificatesClient struct {
	internal       *arm.Client
	subscriptionID string
}

// NewSiteCertificatesClient creates a new instance of SiteCertificatesClient with the specified values.
//   - subscriptionID - Your Azure subscription ID. This is a GUID-formatted string (e.g. 00000000-0000-0000-0000-000000000000).
//   - credential - used to authorize requests. Usually a credential from azidentity.
//   - options - pass nil to accept the default values.
func NewSiteCertificatesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SiteCertificatesClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &SiteCertificatesClient{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// CreateOrUpdate - Create or update a certificate under a given site.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - certificateName - Name of the certificate.
//   - certificateEnvelope - Details of certificate, if it exists already.
//   - options - SiteCertificatesClientCreateOrUpdateOptions contains the optional parameters for the SiteCertificatesClient.CreateOrUpdate
//     method.
func (client *SiteCertificatesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, name string, certificateName string, certificateEnvelope AppCertificate, options *SiteCertificatesClientCreateOrUpdateOptions) (SiteCertificatesClientCreateOrUpdateResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.CreateOrUpdate"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, name, certificateName, certificateEnvelope, options)
	if err != nil {
		return SiteCertificatesClientCreateOrUpdateResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientCreateOrUpdateResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientCreateOrUpdateResponse{}, err
	}
	resp, err := client.createOrUpdateHandleResponse(httpResp)
	return resp, err
}

// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *SiteCertificatesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, name string, certificateName string, certificateEnvelope AppCertificate, _ *SiteCertificatesClientCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/certificates/{certificateName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, certificateEnvelope); err != nil {
		return nil, err
	}
	return req, nil
}

// createOrUpdateHandleResponse handles the CreateOrUpdate response.
func (client *SiteCertificatesClient) createOrUpdateHandleResponse(resp *http.Response) (SiteCertificatesClientCreateOrUpdateResponse, error) {
	result := SiteCertificatesClientCreateOrUpdateResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificate); err != nil {
		return SiteCertificatesClientCreateOrUpdateResponse{}, err
	}
	return result, nil
}

// CreateOrUpdateSlot - Create or update a certificate in a given site and deployment slot.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - slot - Name of the deployment slot. If a slot is not specified, the API will create a binding for the production slot.
//   - certificateName - Name of the certificate.
//   - certificateEnvelope - Details of certificate, if it exists already.
//   - options - SiteCertificatesClientCreateOrUpdateSlotOptions contains the optional parameters for the SiteCertificatesClient.CreateOrUpdateSlot
//     method.
func (client *SiteCertificatesClient) CreateOrUpdateSlot(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, certificateEnvelope AppCertificate, options *SiteCertificatesClientCreateOrUpdateSlotOptions) (SiteCertificatesClientCreateOrUpdateSlotResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.CreateOrUpdateSlot"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.createOrUpdateSlotCreateRequest(ctx, resourceGroupName, name, slot, certificateName, certificateEnvelope, options)
	if err != nil {
		return SiteCertificatesClientCreateOrUpdateSlotResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientCreateOrUpdateSlotResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientCreateOrUpdateSlotResponse{}, err
	}
	resp, err := client.createOrUpdateSlotHandleResponse(httpResp)
	return resp, err
}

// createOrUpdateSlotCreateRequest creates the CreateOrUpdateSlot request.
func (client *SiteCertificatesClient) createOrUpdateSlotCreateRequest(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, certificateEnvelope AppCertificate, _ *SiteCertificatesClientCreateOrUpdateSlotOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/slots/{slot}/certificates/{certificateName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if slot == "" {
		return nil, errors.New("parameter slot cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{slot}", url.PathEscape(slot))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, certificateEnvelope); err != nil {
		return nil, err
	}
	return req, nil
}

// createOrUpdateSlotHandleResponse handles the CreateOrUpdateSlot response.
func (client *SiteCertificatesClient) createOrUpdateSlotHandleResponse(resp *http.Response) (SiteCertificatesClientCreateOrUpdateSlotResponse, error) {
	result := SiteCertificatesClientCreateOrUpdateSlotResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificate); err != nil {
		return SiteCertificatesClientCreateOrUpdateSlotResponse{}, err
	}
	return result, nil
}

// Delete - Delete a certificate from the site.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - certificateName - Name of the certificate.
//   - options - SiteCertificatesClientDeleteOptions contains the optional parameters for the SiteCertificatesClient.Delete method.
func (client *SiteCertificatesClient) Delete(ctx context.Context, resourceGroupName string, name string, certificateName string, options *SiteCertificatesClientDeleteOptions) (SiteCertificatesClientDeleteResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.Delete"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.deleteCreateRequest(ctx, resourceGroupName, name, certificateName, options)
	if err != nil {
		return SiteCertificatesClientDeleteResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientDeleteResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientDeleteResponse{}, err
	}
	return SiteCertificatesClientDeleteResponse{}, nil
}

// deleteCreateRequest creates the Delete request.
func (client *SiteCertificatesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, name string, certificateName string, _ *SiteCertificatesClientDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/certificates/{certificateName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// DeleteSlot - Delete a certificate for a given site and deployment slot.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - slot - Name of the deployment slot. If a slot is not specified, the API will create a binding for the production slot.
//   - certificateName - Name of the certificate.
//   - options - SiteCertificatesClientDeleteSlotOptions contains the optional parameters for the SiteCertificatesClient.DeleteSlot
//     method.
func (client *SiteCertificatesClient) DeleteSlot(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, options *SiteCertificatesClientDeleteSlotOptions) (SiteCertificatesClientDeleteSlotResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.DeleteSlot"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.deleteSlotCreateRequest(ctx, resourceGroupName, name, slot, certificateName, options)
	if err != nil {
		return SiteCertificatesClientDeleteSlotResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientDeleteSlotResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientDeleteSlotResponse{}, err
	}
	return SiteCertificatesClientDeleteSlotResponse{}, nil
}

// deleteSlotCreateRequest creates the DeleteSlot request.
func (client *SiteCertificatesClient) deleteSlotCreateRequest(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, _ *SiteCertificatesClientDeleteSlotOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/slots/{slot}/certificates/{certificateName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if slot == "" {
		return nil, errors.New("parameter slot cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{slot}", url.PathEscape(slot))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// Get - Get a certificate belonging to a given site.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - certificateName - Name of the certificate.
//   - options - SiteCertificatesClientGetOptions contains the optional parameters for the SiteCertificatesClient.Get method.
func (client *SiteCertificatesClient) Get(ctx context.Context, resourceGroupName string, name string, certificateName string, options *SiteCertificatesClientGetOptions) (SiteCertificatesClientGetResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.Get"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getCreateRequest(ctx, resourceGroupName, name, certificateName, options)
	if err != nil {
		return SiteCertificatesClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *SiteCertificatesClient) getCreateRequest(ctx context.Context, resourceGroupName string, name string, certificateName string, _ *SiteCertificatesClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/certificates/{certificateName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getHandleResponse handles the Get response.
func (client *SiteCertificatesClient) getHandleResponse(resp *http.Response) (SiteCertificatesClientGetResponse, error) {
	result := SiteCertificatesClientGetResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificate); err != nil {
		return SiteCertificatesClientGetResponse{}, err
	}
	return result, nil
}

// GetSlot - Get a certificate for a given site and deployment slot.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - slot - Name of the deployment slot. If a slot is not specified, the API will create a binding for the production slot.
//   - certificateName - Name of the certificate.
//   - options - SiteCertificatesClientGetSlotOptions contains the optional parameters for the SiteCertificatesClient.GetSlot
//     method.
func (client *SiteCertificatesClient) GetSlot(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, options *SiteCertificatesClientGetSlotOptions) (SiteCertificatesClientGetSlotResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.GetSlot"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.getSlotCreateRequest(ctx, resourceGroupName, name, slot, certificateName, options)
	if err != nil {
		return SiteCertificatesClientGetSlotResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientGetSlotResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientGetSlotResponse{}, err
	}
	resp, err := client.getSlotHandleResponse(httpResp)
	return resp, err
}

// getSlotCreateRequest creates the GetSlot request.
func (client *SiteCertificatesClient) getSlotCreateRequest(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, _ *SiteCertificatesClientGetSlotOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/slots/{slot}/certificates/{certificateName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if slot == "" {
		return nil, errors.New("parameter slot cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{slot}", url.PathEscape(slot))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// getSlotHandleResponse handles the GetSlot response.
func (client *SiteCertificatesClient) getSlotHandleResponse(resp *http.Response) (SiteCertificatesClientGetSlotResponse, error) {
	result := SiteCertificatesClientGetSlotResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificate); err != nil {
		return SiteCertificatesClientGetSlotResponse{}, err
	}
	return result, nil
}

// NewListPager - Get all certificates in a resource group under a site.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - options - SiteCertificatesClientListOptions contains the optional parameters for the SiteCertificatesClient.NewListPager
//     method.
func (client *SiteCertificatesClient) NewListPager(resourceGroupName string, name string, options *SiteCertificatesClientListOptions) *runtime.Pager[SiteCertificatesClientListResponse] {
	return runtime.NewPager(runtime.PagingHandler[SiteCertificatesClientListResponse]{
		More: func(page SiteCertificatesClientListResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *SiteCertificatesClientListResponse) (SiteCertificatesClientListResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SiteCertificatesClient.NewListPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listCreateRequest(ctx, resourceGroupName, name, options)
			}, nil)
			if err != nil {
				return SiteCertificatesClientListResponse{}, err
			}
			return client.listHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listCreateRequest creates the List request.
func (client *SiteCertificatesClient) listCreateRequest(ctx context.Context, resourceGroupName string, name string, _ *SiteCertificatesClientListOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/certificates"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listHandleResponse handles the List response.
func (client *SiteCertificatesClient) listHandleResponse(resp *http.Response) (SiteCertificatesClientListResponse, error) {
	result := SiteCertificatesClientListResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificateCollection); err != nil {
		return SiteCertificatesClientListResponse{}, err
	}
	return result, nil
}

// NewListSlotPager - Get all certificates in a resource group for a given site and a deployment slot.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - slot - Name of the deployment slot. If a slot is not specified, the API will create a binding for the production slot.
//   - options - SiteCertificatesClientListSlotOptions contains the optional parameters for the SiteCertificatesClient.NewListSlotPager
//     method.
func (client *SiteCertificatesClient) NewListSlotPager(resourceGroupName string, name string, slot string, options *SiteCertificatesClientListSlotOptions) *runtime.Pager[SiteCertificatesClientListSlotResponse] {
	return runtime.NewPager(runtime.PagingHandler[SiteCertificatesClientListSlotResponse]{
		More: func(page SiteCertificatesClientListSlotResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *SiteCertificatesClientListSlotResponse) (SiteCertificatesClientListSlotResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SiteCertificatesClient.NewListSlotPager")
			nextLink := ""
			if page != nil {
				nextLink = *page.NextLink
			}
			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
				return client.listSlotCreateRequest(ctx, resourceGroupName, name, slot, options)
			}, nil)
			if err != nil {
				return SiteCertificatesClientListSlotResponse{}, err
			}
			return client.listSlotHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listSlotCreateRequest creates the ListSlot request.
func (client *SiteCertificatesClient) listSlotCreateRequest(ctx context.Context, resourceGroupName string, name string, slot string, _ *SiteCertificatesClientListSlotOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/slots/{slot}/certificates"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if slot == "" {
		return nil, errors.New("parameter slot cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{slot}", url.PathEscape(slot))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listSlotHandleResponse handles the ListSlot response.
func (client *SiteCertificatesClient) listSlotHandleResponse(resp *http.Response) (SiteCertificatesClientListSlotResponse, error) {
	result := SiteCertificatesClientListSlotResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificateCollection); err != nil {
		return SiteCertificatesClientListSlotResponse{}, err
	}
	return result, nil
}

// Update - Create or update a certificate under a given site.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - certificateName - Name of the certificate.
//   - certificateEnvelope - Details of certificate, if it exists already.
//   - options - SiteCertificatesClientUpdateOptions contains the optional parameters for the SiteCertificatesClient.Update method.
func (client *SiteCertificatesClient) Update(ctx context.Context, resourceGroupName string, name string, certificateName string, certificateEnvelope AppCertificatePatchResource, options *SiteCertificatesClientUpdateOptions) (SiteCertificatesClientUpdateResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.Update"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.updateCreateRequest(ctx, resourceGroupName, name, certificateName, certificateEnvelope, options)
	if err != nil {
		return SiteCertificatesClientUpdateResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientUpdateResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientUpdateResponse{}, err
	}
	resp, err := client.updateHandleResponse(httpResp)
	return resp, err
}

// updateCreateRequest creates the Update request.
func (client *SiteCertificatesClient) updateCreateRequest(ctx context.Context, resourceGroupName string, name string, certificateName string, certificateEnvelope AppCertificatePatchResource, _ *SiteCertificatesClientUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/certificates/{certificateName}"
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, certificateEnvelope); err != nil {
		return nil, err
	}
	return req, nil
}

// updateHandleResponse handles the Update response.
func (client *SiteCertificatesClient) updateHandleResponse(resp *http.Response) (SiteCertificatesClientUpdateResponse, error) {
	result := SiteCertificatesClientUpdateResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificate); err != nil {
		return SiteCertificatesClientUpdateResponse{}, err
	}
	return result, nil
}

// UpdateSlot - Create or update a certificate for a site and deployment slot.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-11-01
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - name - Name of the site.
//   - slot - Name of the deployment slot. If a slot is not specified, the API will create a binding for the production slot.
//   - certificateName - Name of the certificate.
//   - certificateEnvelope - Details of certificate, if it exists already.
//   - options - SiteCertificatesClientUpdateSlotOptions contains the optional parameters for the SiteCertificatesClient.UpdateSlot
//     method.
func (client *SiteCertificatesClient) UpdateSlot(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, certificateEnvelope AppCertificatePatchResource, options *SiteCertificatesClientUpdateSlotOptions) (SiteCertificatesClientUpdateSlotResponse, error) {
	var err error
	const operationName = "SiteCertificatesClient.UpdateSlot"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.updateSlotCreateRequest(ctx, resourceGroupName, name, slot, certificateName, certificateEnvelope, options)
	if err != nil {
		return SiteCertificatesClientUpdateSlotResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return SiteCertificatesClientUpdateSlotResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return SiteCertificatesClientUpdateSlotResponse{}, err
	}
	resp, err := client.updateSlotHandleResponse(httpResp)
	return resp, err
}

// updateSlotCreateRequest creates the UpdateSlot request.
func (client *SiteCertificatesClient) updateSlotCreateRequest(ctx context.Context, resourceGroupName string, name string, slot string, certificateName string, certificateEnvelope AppCertificatePatchResource, _ *SiteCertificatesClientUpdateSlotOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/slots/{slot}/certificates/{certificateName}"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if resourceGroupName == "" {
		return nil, errors.New("parameter resourceGroupName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
	if name == "" {
		return nil, errors.New("parameter name cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{name}", url.PathEscape(name))
	if slot == "" {
		return nil, errors.New("parameter slot cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{slot}", url.PathEscape(slot))
	if certificateName == "" {
		return nil, errors.New("parameter certificateName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{certificateName}", url.PathEscape(certificateName))
	req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", "2024-11-01")
	req.Raw().URL.RawQuery = reqQP.Encode()
	req.Raw().Header["Accept"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, certificateEnvelope); err != nil {
		return nil, err
	}
	return req, nil
}

// updateSlotHandleResponse handles the UpdateSlot response.
func (client *SiteCertificatesClient) updateSlotHandleResponse(resp *http.Response) (SiteCertificatesClientUpdateSlotResponse, error) {
	result := SiteCertificatesClientUpdateSlotResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.AppCertificate); err != nil {
		return SiteCertificatesClientUpdateSlotResponse{}, err
	}
	return result, nil
}
