// 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) Go Code Generator. DO NOT EDIT.

package armenclave

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"
)

// CommunityEndpointsClient - Community Endpoint Interface
// Don't use this type directly, use NewCommunityEndpointsClient() instead.
//
// Generated from API version 2026-03-01-preview
type CommunityEndpointsClient struct {
	internal       *arm.Client
	subscriptionID string
}

// NewCommunityEndpointsClient creates a new instance of CommunityEndpointsClient with the specified values.
//   - subscriptionID - The ID of the target subscription. The value must be an UUID.
//   - credential - used to authorize requests. Usually a credential from azidentity.
//   - options - Contains optional client configuration. Pass nil to accept the default values.
func NewCommunityEndpointsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*CommunityEndpointsClient, error) {
	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
	if err != nil {
		return nil, err
	}
	client := &CommunityEndpointsClient{
		subscriptionID: subscriptionID,
		internal:       cl,
	}
	return client, nil
}

// BeginCreateOrUpdate - Create a CommunityEndpointResource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - communityName - The name of the communityResource Resource
//   - communityEndpointName - The name of the Community Endpoint Resource
//   - resource - Resource create parameters.
//   - options - CommunityEndpointsClientBeginCreateOrUpdateOptions contains the optional parameters for the CommunityEndpointsClient.BeginCreateOrUpdate
//     method.
func (client *CommunityEndpointsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, resource CommunityEndpointResource, options *CommunityEndpointsClientBeginCreateOrUpdateOptions) (*runtime.Poller[CommunityEndpointsClientCreateOrUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.createOrUpdate(ctx, resourceGroupName, communityName, communityEndpointName, resource, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CommunityEndpointsClientCreateOrUpdateResponse]{
			FinalStateVia: runtime.FinalStateViaAzureAsyncOp,
			Tracer:        client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[CommunityEndpointsClientCreateOrUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// CreateOrUpdate - Create a CommunityEndpointResource
// If the operation fails it returns an *azcore.ResponseError type.
func (client *CommunityEndpointsClient) createOrUpdate(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, resource CommunityEndpointResource, options *CommunityEndpointsClientBeginCreateOrUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "CommunityEndpointsClient.BeginCreateOrUpdate"
	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, communityName, communityEndpointName, resource, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *CommunityEndpointsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, resource CommunityEndpointResource, _ *CommunityEndpointsClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints/{communityEndpointName}"
	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 communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	if communityEndpointName == "" {
		return nil, errors.New("parameter communityEndpointName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityEndpointName}", url.PathEscape(communityEndpointName))
	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", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, resource); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginDelete - Delete a CommunityEndpointResource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - communityName - The name of the communityResource Resource
//   - communityEndpointName - The name of the Community Endpoint Resource
//   - options - CommunityEndpointsClientBeginDeleteOptions contains the optional parameters for the CommunityEndpointsClient.BeginDelete
//     method.
func (client *CommunityEndpointsClient) BeginDelete(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, options *CommunityEndpointsClientBeginDeleteOptions) (*runtime.Poller[CommunityEndpointsClientDeleteResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.deleteOperation(ctx, resourceGroupName, communityName, communityEndpointName, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CommunityEndpointsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[CommunityEndpointsClientDeleteResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Delete - Delete a CommunityEndpointResource
// If the operation fails it returns an *azcore.ResponseError type.
func (client *CommunityEndpointsClient) deleteOperation(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, options *CommunityEndpointsClientBeginDeleteOptions) (*http.Response, error) {
	var err error
	const operationName = "CommunityEndpointsClient.BeginDelete"
	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, communityName, communityEndpointName, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusAccepted, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// deleteCreateRequest creates the Delete request.
func (client *CommunityEndpointsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, _ *CommunityEndpointsClientBeginDeleteOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints/{communityEndpointName}"
	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 communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	if communityEndpointName == "" {
		return nil, errors.New("parameter communityEndpointName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityEndpointName}", url.PathEscape(communityEndpointName))
	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", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	return req, nil
}

// Get - Get a CommunityEndpointResource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - communityName - The name of the communityResource Resource
//   - communityEndpointName - The name of the Community Endpoint Resource
//   - options - CommunityEndpointsClientGetOptions contains the optional parameters for the CommunityEndpointsClient.Get method.
func (client *CommunityEndpointsClient) Get(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, options *CommunityEndpointsClientGetOptions) (CommunityEndpointsClientGetResponse, error) {
	var err error
	const operationName = "CommunityEndpointsClient.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, communityName, communityEndpointName, options)
	if err != nil {
		return CommunityEndpointsClientGetResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return CommunityEndpointsClientGetResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return CommunityEndpointsClientGetResponse{}, err
	}
	resp, err := client.getHandleResponse(httpResp)
	return resp, err
}

// getCreateRequest creates the Get request.
func (client *CommunityEndpointsClient) getCreateRequest(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, _ *CommunityEndpointsClientGetOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints/{communityEndpointName}"
	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 communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	if communityEndpointName == "" {
		return nil, errors.New("parameter communityEndpointName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityEndpointName}", url.PathEscape(communityEndpointName))
	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", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

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

// BeginHandleApprovalCreation - Callback that triggers on approval state change.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - communityName - The name of the communityResource Resource
//   - communityEndpointName - The name of the Community Endpoint Resource
//   - body - The content of the action request
//   - options - CommunityEndpointsClientBeginHandleApprovalCreationOptions contains the optional parameters for the CommunityEndpointsClient.BeginHandleApprovalCreation
//     method.
func (client *CommunityEndpointsClient) BeginHandleApprovalCreation(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, body ApprovalCallbackRequest, options *CommunityEndpointsClientBeginHandleApprovalCreationOptions) (*runtime.Poller[CommunityEndpointsClientHandleApprovalCreationResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.handleApprovalCreation(ctx, resourceGroupName, communityName, communityEndpointName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CommunityEndpointsClientHandleApprovalCreationResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[CommunityEndpointsClientHandleApprovalCreationResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// HandleApprovalCreation - Callback that triggers on approval state change.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *CommunityEndpointsClient) handleApprovalCreation(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, body ApprovalCallbackRequest, options *CommunityEndpointsClientBeginHandleApprovalCreationOptions) (*http.Response, error) {
	var err error
	const operationName = "CommunityEndpointsClient.BeginHandleApprovalCreation"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.handleApprovalCreationCreateRequest(ctx, resourceGroupName, communityName, communityEndpointName, body, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// handleApprovalCreationCreateRequest creates the HandleApprovalCreation request.
func (client *CommunityEndpointsClient) handleApprovalCreationCreateRequest(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, body ApprovalCallbackRequest, _ *CommunityEndpointsClientBeginHandleApprovalCreationOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints/{communityEndpointName}/handleApprovalCreation"
	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 communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	if communityEndpointName == "" {
		return nil, errors.New("parameter communityEndpointName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityEndpointName}", url.PathEscape(communityEndpointName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// BeginHandleApprovalDeletion - Callback that triggers on approval deletion state change.
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - communityName - The name of the communityResource Resource
//   - communityEndpointName - The name of the Community Endpoint Resource
//   - body - The content of the action request
//   - options - CommunityEndpointsClientBeginHandleApprovalDeletionOptions contains the optional parameters for the CommunityEndpointsClient.BeginHandleApprovalDeletion
//     method.
func (client *CommunityEndpointsClient) BeginHandleApprovalDeletion(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, body ApprovalDeletionCallbackRequest, options *CommunityEndpointsClientBeginHandleApprovalDeletionOptions) (*runtime.Poller[CommunityEndpointsClientHandleApprovalDeletionResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.handleApprovalDeletion(ctx, resourceGroupName, communityName, communityEndpointName, body, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CommunityEndpointsClientHandleApprovalDeletionResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[CommunityEndpointsClientHandleApprovalDeletionResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// HandleApprovalDeletion - Callback that triggers on approval deletion state change.
// If the operation fails it returns an *azcore.ResponseError type.
func (client *CommunityEndpointsClient) handleApprovalDeletion(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, body ApprovalDeletionCallbackRequest, options *CommunityEndpointsClientBeginHandleApprovalDeletionOptions) (*http.Response, error) {
	var err error
	const operationName = "CommunityEndpointsClient.BeginHandleApprovalDeletion"
	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
	defer func() { endSpan(err) }()
	req, err := client.handleApprovalDeletionCreateRequest(ctx, resourceGroupName, communityName, communityEndpointName, body, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// handleApprovalDeletionCreateRequest creates the HandleApprovalDeletion request.
func (client *CommunityEndpointsClient) handleApprovalDeletionCreateRequest(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, body ApprovalDeletionCallbackRequest, _ *CommunityEndpointsClientBeginHandleApprovalDeletionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints/{communityEndpointName}/handleApprovalDeletion"
	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 communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	if communityEndpointName == "" {
		return nil, errors.New("parameter communityEndpointName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityEndpointName}", url.PathEscape(communityEndpointName))
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("api-version", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, body); err != nil {
		return nil, err
	}
	return req, nil
}

// NewListByCommunityResourcePager - List CommunityEndpointResource resources by CommunityResource
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - communityName - The name of the communityResource Resource
//   - options - CommunityEndpointsClientListByCommunityResourceOptions contains the optional parameters for the CommunityEndpointsClient.NewListByCommunityResourcePager
//     method.
func (client *CommunityEndpointsClient) NewListByCommunityResourcePager(resourceGroupName string, communityName string, options *CommunityEndpointsClientListByCommunityResourceOptions) *runtime.Pager[CommunityEndpointsClientListByCommunityResourceResponse] {
	return runtime.NewPager(runtime.PagingHandler[CommunityEndpointsClientListByCommunityResourceResponse]{
		More: func(page CommunityEndpointsClientListByCommunityResourceResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *CommunityEndpointsClientListByCommunityResourceResponse) (CommunityEndpointsClientListByCommunityResourceResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CommunityEndpointsClient.NewListByCommunityResourcePager")
			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.listByCommunityResourceCreateRequest(ctx, resourceGroupName, communityName, options)
			}, nil)
			if err != nil {
				return CommunityEndpointsClientListByCommunityResourceResponse{}, err
			}
			return client.listByCommunityResourceHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listByCommunityResourceCreateRequest creates the ListByCommunityResource request.
func (client *CommunityEndpointsClient) listByCommunityResourceCreateRequest(ctx context.Context, resourceGroupName string, communityName string, _ *CommunityEndpointsClientListByCommunityResourceOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints"
	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 communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	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", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listByCommunityResourceHandleResponse handles the ListByCommunityResource response.
func (client *CommunityEndpointsClient) listByCommunityResourceHandleResponse(resp *http.Response) (CommunityEndpointsClientListByCommunityResourceResponse, error) {
	result := CommunityEndpointsClientListByCommunityResourceResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.CommunityEndpointResourceListResult); err != nil {
		return CommunityEndpointsClientListByCommunityResourceResponse{}, err
	}
	return result, nil
}

// NewListBySubscriptionPager - List CommunityEndpointResource resources by subscription ID
//   - communityName - The name of the communityResource Resource
//   - options - CommunityEndpointsClientListBySubscriptionOptions contains the optional parameters for the CommunityEndpointsClient.NewListBySubscriptionPager
//     method.
func (client *CommunityEndpointsClient) NewListBySubscriptionPager(communityName string, options *CommunityEndpointsClientListBySubscriptionOptions) *runtime.Pager[CommunityEndpointsClientListBySubscriptionResponse] {
	return runtime.NewPager(runtime.PagingHandler[CommunityEndpointsClientListBySubscriptionResponse]{
		More: func(page CommunityEndpointsClientListBySubscriptionResponse) bool {
			return page.NextLink != nil && len(*page.NextLink) > 0
		},
		Fetcher: func(ctx context.Context, page *CommunityEndpointsClientListBySubscriptionResponse) (CommunityEndpointsClientListBySubscriptionResponse, error) {
			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "CommunityEndpointsClient.NewListBySubscriptionPager")
			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.listBySubscriptionCreateRequest(ctx, communityName, options)
			}, nil)
			if err != nil {
				return CommunityEndpointsClientListBySubscriptionResponse{}, err
			}
			return client.listBySubscriptionHandleResponse(resp)
		},
		Tracer: client.internal.Tracer(),
	})
}

// listBySubscriptionCreateRequest creates the ListBySubscription request.
func (client *CommunityEndpointsClient) listBySubscriptionCreateRequest(ctx context.Context, communityName string, _ *CommunityEndpointsClientListBySubscriptionOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints"
	if client.subscriptionID == "" {
		return nil, errors.New("parameter client.subscriptionID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
	if communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	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", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	return req, nil
}

// listBySubscriptionHandleResponse handles the ListBySubscription response.
func (client *CommunityEndpointsClient) listBySubscriptionHandleResponse(resp *http.Response) (CommunityEndpointsClientListBySubscriptionResponse, error) {
	result := CommunityEndpointsClientListBySubscriptionResponse{}
	if err := runtime.UnmarshalAsJSON(resp, &result.CommunityEndpointResourceListResult); err != nil {
		return CommunityEndpointsClientListBySubscriptionResponse{}, err
	}
	return result, nil
}

// BeginUpdate - Update a CommunityEndpointResource
// If the operation fails it returns an *azcore.ResponseError type.
//   - resourceGroupName - The name of the resource group. The name is case insensitive.
//   - communityName - The name of the communityResource Resource
//   - communityEndpointName - The name of the Community Endpoint Resource
//   - properties - The resource properties to be updated.
//   - options - CommunityEndpointsClientBeginUpdateOptions contains the optional parameters for the CommunityEndpointsClient.BeginUpdate
//     method.
func (client *CommunityEndpointsClient) BeginUpdate(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, properties CommunityEndpointPatchModel, options *CommunityEndpointsClientBeginUpdateOptions) (*runtime.Poller[CommunityEndpointsClientUpdateResponse], error) {
	if options == nil || options.ResumeToken == "" {
		resp, err := client.update(ctx, resourceGroupName, communityName, communityEndpointName, properties, options)
		if err != nil {
			return nil, err
		}
		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[CommunityEndpointsClientUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
		return poller, err
	} else {
		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[CommunityEndpointsClientUpdateResponse]{
			Tracer: client.internal.Tracer(),
		})
	}
}

// Update - Update a CommunityEndpointResource
// If the operation fails it returns an *azcore.ResponseError type.
func (client *CommunityEndpointsClient) update(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, properties CommunityEndpointPatchModel, options *CommunityEndpointsClientBeginUpdateOptions) (*http.Response, error) {
	var err error
	const operationName = "CommunityEndpointsClient.BeginUpdate"
	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, communityName, communityEndpointName, properties, options)
	if err != nil {
		return nil, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return nil, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) {
		err = runtime.NewResponseError(httpResp)
		return nil, err
	}
	return httpResp, nil
}

// updateCreateRequest creates the Update request.
func (client *CommunityEndpointsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, communityName string, communityEndpointName string, properties CommunityEndpointPatchModel, _ *CommunityEndpointsClientBeginUpdateOptions) (*policy.Request, error) {
	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mission/communities/{communityName}/communityEndpoints/{communityEndpointName}"
	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 communityName == "" {
		return nil, errors.New("parameter communityName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityName}", url.PathEscape(communityName))
	if communityEndpointName == "" {
		return nil, errors.New("parameter communityEndpointName cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{communityEndpointName}", url.PathEscape(communityEndpointName))
	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", version20260301Preview)
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/json"}
	req.Raw().Header["Content-Type"] = []string{"application/json"}
	if err := runtime.MarshalAsJSON(req, properties); err != nil {
		return nil, err
	}
	return req, nil
}
