// 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 generated

import (
	"context"
	"encoding/xml"
	"errors"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"time"
)

// QueueClient contains the methods for the Queue group.
// Don't use this type directly, use a constructor function instead.
//
// Generated from API version 2026-04-06
type QueueClient struct {
	internal *azcore.Client
	url      string
}

// Clear - Deletes all messages from the specified queue.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientClearOptions contains the optional parameters for the QueueClient.Clear method.
func (client *QueueClient) Clear(ctx context.Context, options *QueueClientClearOptions) (MessagesClientClearResponse, error) {
	var err error
	req, err := client.clearCreateRequest(ctx, options)
	if err != nil {
		return MessagesClientClearResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return MessagesClientClearResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return MessagesClientClearResponse{}, err
	}
	resp, err := client.clearHandleResponse(httpResp)
	return resp, err
}

// clearCreateRequest creates the Clear request.
func (client *QueueClient) clearCreateRequest(ctx context.Context, options *QueueClientClearOptions) (*policy.Request, error) {
	urlPath := "/messages"
	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// clearHandleResponse handles the Clear response.
func (client *QueueClient) clearHandleResponse(resp *http.Response) (MessagesClientClearResponse, error) {
	result := MessagesClientClearResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return MessagesClientClearResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}

// Create - Creates a new queue. If a queue with the same name already exists, the operation succeeds when the metadata
// is identical. If the metadata differs, the operation fails.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientCreateOptions contains the optional parameters for the QueueClient.Create method.
func (client *QueueClient) Create(ctx context.Context, options *QueueClientCreateOptions) (QueueClientCreateResponse, error) {
	var err error
	req, err := client.createCreateRequest(ctx, options)
	if err != nil {
		return QueueClientCreateResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return QueueClientCreateResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusCreated, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return QueueClientCreateResponse{}, err
	}
	resp, err := client.createHandleResponse(httpResp)
	return resp, err
}

// createCreateRequest creates the Create request.
func (client *QueueClient) createCreateRequest(ctx context.Context, options *QueueClientCreateOptions) (*policy.Request, error) {
	req, err := runtime.NewRequest(ctx, http.MethodPut, client.url)
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	if options != nil && options.Metadata != nil {
		for k, v := range options.Metadata {
			if v != nil {
				req.Raw().Header["x-ms-meta-"+k] = []string{*v}
			}
		}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// createHandleResponse handles the Create response.
func (client *QueueClient) createHandleResponse(resp *http.Response) (QueueClientCreateResponse, error) {
	result := QueueClientCreateResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return QueueClientCreateResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}

// Delete - Permanently deletes the specified queue.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientDeleteOptions contains the optional parameters for the QueueClient.Delete method.
func (client *QueueClient) Delete(ctx context.Context, options *QueueClientDeleteOptions) (QueueClientDeleteResponse, error) {
	var err error
	req, err := client.deleteCreateRequest(ctx, options)
	if err != nil {
		return QueueClientDeleteResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return QueueClientDeleteResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return QueueClientDeleteResponse{}, err
	}
	resp, err := client.deleteHandleResponse(httpResp)
	return resp, err
}

// deleteCreateRequest creates the Delete request.
func (client *QueueClient) deleteCreateRequest(ctx context.Context, options *QueueClientDeleteOptions) (*policy.Request, error) {
	req, err := runtime.NewRequest(ctx, http.MethodDelete, client.url)
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// deleteHandleResponse handles the Delete response.
func (client *QueueClient) deleteHandleResponse(resp *http.Response) (QueueClientDeleteResponse, error) {
	result := QueueClientDeleteResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return QueueClientDeleteResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}

// DeleteMessage - Deletes the specified message.
// If the operation fails it returns an *azcore.ResponseError type.
//   - messageID - The ID of the queue message.
//   - popReceipt - An opaque value required to delete the message. If deletion fails using this
//     PopReceipt then the message has been dequeued by another client.
//   - options - QueueClientDeleteMessageOptions contains the optional parameters for the QueueClient.DeleteMessage method.
func (client *QueueClient) DeleteMessage(ctx context.Context, messageID string, popReceipt string, options *QueueClientDeleteMessageOptions) (MessageIDClientDeleteResponse, error) {
	var err error
	req, err := client.deleteMessageCreateRequest(ctx, messageID, popReceipt, options)
	if err != nil {
		return MessageIDClientDeleteResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return MessageIDClientDeleteResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return MessageIDClientDeleteResponse{}, err
	}
	resp, err := client.deleteMessageHandleResponse(httpResp)
	return resp, err
}

// deleteMessageCreateRequest creates the DeleteMessage request.
func (client *QueueClient) deleteMessageCreateRequest(ctx context.Context, messageID string, popReceipt string, options *QueueClientDeleteMessageOptions) (*policy.Request, error) {
	urlPath := "/messages/{messageId}"
	if messageID == "" {
		return nil, errors.New("parameter messageID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{messageId}", url.PathEscape(messageID))
	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("popreceipt", popReceipt)
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// deleteMessageHandleResponse handles the DeleteMessage response.
func (client *QueueClient) deleteMessageHandleResponse(resp *http.Response) (MessageIDClientDeleteResponse, error) {
	result := MessageIDClientDeleteResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return MessageIDClientDeleteResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}

// GetAccessPolicy - Gets the access policy for the specified queue.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientGetAccessPolicyOptions contains the optional parameters for the QueueClient.GetAccessPolicy method.
func (client *QueueClient) GetAccessPolicy(ctx context.Context, options *QueueClientGetAccessPolicyOptions) (QueueClientGetAccessPolicyResponse, error) {
	var err error
	req, err := client.getAccessPolicyCreateRequest(ctx, options)
	if err != nil {
		return QueueClientGetAccessPolicyResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return QueueClientGetAccessPolicyResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return QueueClientGetAccessPolicyResponse{}, err
	}
	resp, err := client.getAccessPolicyHandleResponse(httpResp)
	return resp, err
}

// getAccessPolicyCreateRequest creates the GetAccessPolicy request.
func (client *QueueClient) getAccessPolicyCreateRequest(ctx context.Context, options *QueueClientGetAccessPolicyOptions) (*policy.Request, error) {
	urlPath := "?comp=acl"
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/xml"}
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// getAccessPolicyHandleResponse handles the GetAccessPolicy response.
func (client *QueueClient) getAccessPolicyHandleResponse(resp *http.Response) (QueueClientGetAccessPolicyResponse, error) {
	result := QueueClientGetAccessPolicyResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return QueueClientGetAccessPolicyResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	if err := runtime.UnmarshalAsXML(resp, &result); err != nil {
		return QueueClientGetAccessPolicyResponse{}, err
	}
	return result, nil
}

// GetProperties - Returns all user-defined metadata and system properties for the specified queue.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientGetPropertiesOptions contains the optional parameters for the QueueClient.GetProperties method.
func (client *QueueClient) GetProperties(ctx context.Context, options *QueueClientGetPropertiesOptions) (QueueClientGetPropertiesResponse, error) {
	var err error
	req, err := client.getPropertiesCreateRequest(ctx, options)
	if err != nil {
		return QueueClientGetPropertiesResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return QueueClientGetPropertiesResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return QueueClientGetPropertiesResponse{}, err
	}
	resp, err := client.getPropertiesHandleResponse(httpResp)
	return resp, err
}

// getPropertiesCreateRequest creates the GetProperties request.
func (client *QueueClient) getPropertiesCreateRequest(ctx context.Context, options *QueueClientGetPropertiesOptions) (*policy.Request, error) {
	urlPath := "?comp=metadata"
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// getPropertiesHandleResponse handles the GetProperties response.
func (client *QueueClient) getPropertiesHandleResponse(resp *http.Response) (QueueClientGetPropertiesResponse, error) {
	result := QueueClientGetPropertiesResponse{}
	if val := resp.Header.Get("x-ms-approximate-messages-count"); val != "" {
		approximateMessagesCount, err := strconv.ParseInt(val, 10, 64)
		if err != nil {
			return QueueClientGetPropertiesResponse{}, err
		}
		result.ApproximateMessagesCount = &approximateMessagesCount
	}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return QueueClientGetPropertiesResponse{}, err
		}
		result.Date = &date
	}
	for hh := range resp.Header {
		if len(hh) > len("x-ms-meta-") && strings.EqualFold(hh[:len("x-ms-meta-")], "x-ms-meta-") {
			if result.Metadata == nil {
				result.Metadata = map[string]*string{}
			}
			result.Metadata[hh[len("x-ms-meta-"):]] = to.Ptr(resp.Header.Get(hh))
		}
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}

// PeekMessages - Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientPeekMessagesOptions contains the optional parameters for the QueueClient.PeekMessages method.
func (client *QueueClient) PeekMessages(ctx context.Context, options *QueueClientPeekMessagesOptions) (MessagesClientPeekResponse, error) {
	var err error
	req, err := client.peekMessagesCreateRequest(ctx, options)
	if err != nil {
		return MessagesClientPeekResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return MessagesClientPeekResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return MessagesClientPeekResponse{}, err
	}
	resp, err := client.peekMessagesHandleResponse(httpResp)
	return resp, err
}

// peekMessagesCreateRequest creates the PeekMessages request.
func (client *QueueClient) peekMessagesCreateRequest(ctx context.Context, options *QueueClientPeekMessagesOptions) (*policy.Request, error) {
	urlPath := "/messages?peekonly=true"
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.NumberOfMessages != nil {
		reqQP.Set("numofmessages", strconv.FormatInt(int64(*options.NumberOfMessages), 10))
	}
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/xml"}
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// peekMessagesHandleResponse handles the PeekMessages response.
func (client *QueueClient) peekMessagesHandleResponse(resp *http.Response) (MessagesClientPeekResponse, error) {
	result := MessagesClientPeekResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return MessagesClientPeekResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	if err := runtime.UnmarshalAsXML(resp, &result); err != nil {
		return MessagesClientPeekResponse{}, err
	}
	return result, nil
}

// ReceiveMessages - Retrieves one or more messages from the front of the queue.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientReceiveMessagesOptions contains the optional parameters for the QueueClient.ReceiveMessages method.
func (client *QueueClient) ReceiveMessages(ctx context.Context, options *QueueClientReceiveMessagesOptions) (MessagesClientDequeueResponse, error) {
	var err error
	req, err := client.receiveMessagesCreateRequest(ctx, options)
	if err != nil {
		return MessagesClientDequeueResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return MessagesClientDequeueResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
		err = runtime.NewResponseError(httpResp)
		return MessagesClientDequeueResponse{}, err
	}
	resp, err := client.receiveMessagesHandleResponse(httpResp)
	return resp, err
}

// receiveMessagesCreateRequest creates the ReceiveMessages request.
func (client *QueueClient) receiveMessagesCreateRequest(ctx context.Context, options *QueueClientReceiveMessagesOptions) (*policy.Request, error) {
	urlPath := "/messages"
	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.NumberOfMessages != nil {
		reqQP.Set("numofmessages", strconv.FormatInt(int64(*options.NumberOfMessages), 10))
	}
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	if options != nil && options.VisibilityTimeout != nil {
		reqQP.Set("visibilitytimeout", strconv.FormatInt(int64(*options.VisibilityTimeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/xml"}
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// receiveMessagesHandleResponse handles the ReceiveMessages response.
func (client *QueueClient) receiveMessagesHandleResponse(resp *http.Response) (MessagesClientDequeueResponse, error) {
	result := MessagesClientDequeueResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return MessagesClientDequeueResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	if err := runtime.UnmarshalAsXML(resp, &result); err != nil {
		return MessagesClientDequeueResponse{}, err
	}
	return result, nil
}

// SendMessage - Adds a new message to the back of the message queue. A visibility timeout
// can also be specified to make the message invisible until the visibility timeout
// expires.
// If the operation fails it returns an *azcore.ResponseError type.
//   - queueMessage - The queue message. The message must be in a format that can be included in an XML request with UTF-8
//     encoding. The encoded message can be up to 64 KB in size.
//   - options - QueueClientSendMessageOptions contains the optional parameters for the QueueClient.SendMessage method.
func (client *QueueClient) SendMessage(ctx context.Context, queueMessage QueueMessage, options *QueueClientSendMessageOptions) (MessagesClientEnqueueResponse, error) {
	var err error
	req, err := client.sendMessageCreateRequest(ctx, queueMessage, options)
	if err != nil {
		return MessagesClientEnqueueResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return MessagesClientEnqueueResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusCreated) {
		err = runtime.NewResponseError(httpResp)
		return MessagesClientEnqueueResponse{}, err
	}
	resp, err := client.sendMessageHandleResponse(httpResp)
	return resp, err
}

// sendMessageCreateRequest creates the SendMessage request.
func (client *QueueClient) sendMessageCreateRequest(ctx context.Context, queueMessage QueueMessage, options *QueueClientSendMessageOptions) (*policy.Request, error) {
	urlPath := "/messages"
	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.MessageTimeToLive != nil {
		reqQP.Set("messagettl", strconv.FormatInt(int64(*options.MessageTimeToLive), 10))
	}
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	if options != nil && options.VisibilityTimeout != nil {
		reqQP.Set("visibilitytimeout", strconv.FormatInt(int64(*options.VisibilityTimeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	req.Raw().Header["Accept"] = []string{"application/xml"}
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	req.Raw().Header["Content-Type"] = []string{"application/xml"}
	if err := runtime.MarshalAsXML(req, queueMessage); err != nil {
		return nil, err
	}
	return req, nil
}

// sendMessageHandleResponse handles the SendMessage response.
func (client *QueueClient) sendMessageHandleResponse(resp *http.Response) (MessagesClientEnqueueResponse, error) {
	result := MessagesClientEnqueueResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return MessagesClientEnqueueResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	if err := runtime.UnmarshalAsXML(resp, &result); err != nil {
		return MessagesClientEnqueueResponse{}, err
	}
	return result, nil
}

// SetAccessPolicy - Sets the permissions for the specified queue.
// If the operation fails it returns an *azcore.ResponseError type.
//   - queueACL - The access control list.
//   - options - QueueClientSetAccessPolicyOptions contains the optional parameters for the QueueClient.SetAccessPolicy method.
func (client *QueueClient) SetAccessPolicy(ctx context.Context, queueACL []*SignedIdentifier, options *QueueClientSetAccessPolicyOptions) (QueueClientSetAccessPolicyResponse, error) {
	var err error
	req, err := client.setAccessPolicyCreateRequest(ctx, queueACL, options)
	if err != nil {
		return QueueClientSetAccessPolicyResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return QueueClientSetAccessPolicyResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return QueueClientSetAccessPolicyResponse{}, err
	}
	resp, err := client.setAccessPolicyHandleResponse(httpResp)
	return resp, err
}

// setAccessPolicyCreateRequest creates the SetAccessPolicy request.
func (client *QueueClient) setAccessPolicyCreateRequest(ctx context.Context, queueACL []*SignedIdentifier, options *QueueClientSetAccessPolicyOptions) (*policy.Request, error) {
	urlPath := "?comp=acl"
	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	type wrapper struct {
		XMLName  xml.Name             `xml:"SignedIdentifiers"`
		QueueACL *[]*SignedIdentifier `xml:"SignedIdentifier"`
	}
	req.Raw().Header["Content-Type"] = []string{"application/xml"}
	if err := runtime.MarshalAsXML(req, wrapper{QueueACL: &queueACL}); err != nil {
		return nil, err
	}
	return req, nil
}

// setAccessPolicyHandleResponse handles the SetAccessPolicy response.
func (client *QueueClient) setAccessPolicyHandleResponse(resp *http.Response) (QueueClientSetAccessPolicyResponse, error) {
	result := QueueClientSetAccessPolicyResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return QueueClientSetAccessPolicyResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}

// SetMetadata - Sets user-defined metadata for the specified queue.
// If the operation fails it returns an *azcore.ResponseError type.
//   - options - QueueClientSetMetadataOptions contains the optional parameters for the QueueClient.SetMetadata method.
func (client *QueueClient) SetMetadata(ctx context.Context, options *QueueClientSetMetadataOptions) (QueueClientSetMetadataResponse, error) {
	var err error
	req, err := client.setMetadataCreateRequest(ctx, options)
	if err != nil {
		return QueueClientSetMetadataResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return QueueClientSetMetadataResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return QueueClientSetMetadataResponse{}, err
	}
	resp, err := client.setMetadataHandleResponse(httpResp)
	return resp, err
}

// setMetadataCreateRequest creates the SetMetadata request.
func (client *QueueClient) setMetadataCreateRequest(ctx context.Context, options *QueueClientSetMetadataOptions) (*policy.Request, error) {
	urlPath := "?comp=metadata"
	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	if options != nil && options.Metadata != nil {
		for k, v := range options.Metadata {
			if v != nil {
				req.Raw().Header["x-ms-meta-"+k] = []string{*v}
			}
		}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	return req, nil
}

// setMetadataHandleResponse handles the SetMetadata response.
func (client *QueueClient) setMetadataHandleResponse(resp *http.Response) (QueueClientSetMetadataResponse, error) {
	result := QueueClientSetMetadataResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return QueueClientSetMetadataResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}

// UpdateMessage - Updates the visibility timeout of a message. This operation can also be used to update the contents of
// a message.
// If the operation fails it returns an *azcore.ResponseError type.
//   - messageID - The ID of the queue message.
//   - popReceipt - An opaque value required to delete the message. If deletion fails using this
//     PopReceipt then the message has been dequeued by another client.
//   - visibilityTimeout - Specifies the new visibility timeout value, in seconds, relative to server time. A specified value
//     must be
//     larger than or equal to 1 second, and cannot be larger than 7 days. The visibility timeout of a message
//     can be set to a value later than the expiry time.
//   - queueMessage - The queue message. The message must be in a format that can be included in
//     an XML request with UTF-8 encoding. The encoded message can be up to 64 KB in size.
//   - options - QueueClientUpdateMessageOptions contains the optional parameters for the QueueClient.UpdateMessage method.
func (client *QueueClient) UpdateMessage(ctx context.Context, messageID string, popReceipt string, visibilityTimeout int32, queueMessage QueueMessage, options *QueueClientUpdateMessageOptions) (MessageIDClientUpdateResponse, error) {
	var err error
	req, err := client.updateMessageCreateRequest(ctx, messageID, popReceipt, visibilityTimeout, queueMessage, options)
	if err != nil {
		return MessageIDClientUpdateResponse{}, err
	}
	httpResp, err := client.internal.Pipeline().Do(req)
	if err != nil {
		return MessageIDClientUpdateResponse{}, err
	}
	if !runtime.HasStatusCode(httpResp, http.StatusNoContent) {
		err = runtime.NewResponseError(httpResp)
		return MessageIDClientUpdateResponse{}, err
	}
	resp, err := client.updateMessageHandleResponse(httpResp)
	return resp, err
}

// updateMessageCreateRequest creates the UpdateMessage request.
func (client *QueueClient) updateMessageCreateRequest(ctx context.Context, messageID string, popReceipt string, visibilityTimeout int32, queueMessage QueueMessage, options *QueueClientUpdateMessageOptions) (*policy.Request, error) {
	urlPath := "/messages/{messageId}"
	if messageID == "" {
		return nil, errors.New("parameter messageID cannot be empty")
	}
	urlPath = strings.ReplaceAll(urlPath, "{messageId}", url.PathEscape(messageID))
	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.url, urlPath))
	if err != nil {
		return nil, err
	}
	reqQP := req.Raw().URL.Query()
	reqQP.Set("popreceipt", popReceipt)
	if options != nil && options.Timeout != nil {
		reqQP.Set("timeout", strconv.FormatInt(int64(*options.Timeout), 10))
	}
	reqQP.Set("visibilitytimeout", strconv.FormatInt(int64(visibilityTimeout), 10))
	req.Raw().URL.RawQuery = strings.ReplaceAll(reqQP.Encode(), "+", "%20")
	if options != nil && options.RequestID != nil {
		req.Raw().Header["x-ms-client-request-id"] = []string{*options.RequestID}
	}
	req.Raw().Header["x-ms-version"] = []string{version20260406}
	req.Raw().Header["Content-Type"] = []string{"application/xml"}
	if err := runtime.MarshalAsXML(req, queueMessage); err != nil {
		return nil, err
	}
	return req, nil
}

// updateMessageHandleResponse handles the UpdateMessage response.
func (client *QueueClient) updateMessageHandleResponse(resp *http.Response) (MessageIDClientUpdateResponse, error) {
	result := MessageIDClientUpdateResponse{}
	if val := resp.Header.Get("x-ms-client-request-id"); val != "" {
		result.ClientRequestID = &val
	}
	if val := resp.Header.Get("Date"); val != "" {
		date, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return MessageIDClientUpdateResponse{}, err
		}
		result.Date = &date
	}
	if val := resp.Header.Get("x-ms-popreceipt"); val != "" {
		result.PopReceipt = &val
	}
	if val := resp.Header.Get("x-ms-request-id"); val != "" {
		result.RequestID = &val
	}
	if val := resp.Header.Get("x-ms-time-next-visible"); val != "" {
		timeNextVisible, err := time.Parse(time.RFC1123, val)
		if err != nil {
			return MessageIDClientUpdateResponse{}, err
		}
		result.TimeNextVisible = &timeNextVisible
	}
	if val := resp.Header.Get("x-ms-version"); val != "" {
		result.Version = &val
	}
	return result, nil
}
