func (q *Queue) DeleteMessageBatch(receiptHandles ...*string) error {
	entries := make([]*sqs.DeleteMessageBatchRequestEntry, len(receiptHandles))
	id2index := make(map[string]int)
	for i, rh := range receiptHandles {
		id := aws.String(fmt.Sprintf("msg-%d", i))
		entries[i] = &sqs.DeleteMessageBatchRequestEntry{
			Id:            id,
			ReceiptHandle: rh,
		}
		id2index[*id] = i
	}
	req := &sqs.DeleteMessageBatchInput{
		Entries:  entries,
		QueueUrl: q.URL,
	}
	resp, err := q.SQS.DeleteMessageBatch(req)
	if err != nil {
		return err
	}
	return NewBatchError(id2index, resp.Failed)
}
DeleteMessageBatch deletes messages from SQS queue.
package queue
import (
	"fmt"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/sqs"
	"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
	multierror "github.com/hashicorp/go-multierror"
	"github.com/nabeken/aws-go-sqs/v3/queue/option"
)
type Queue struct {
	SQS sqsiface.SQSAPI
	URL *string
}
func New(s sqsiface.SQSAPI, name string) (*Queue, error) {
	u, err := GetQueueURL(s, name)
	if err != nil {
		return nil, err
	}
	return &Queue{
		SQS: s,
		URL: u,
	}, nil
}
func MustNew(s sqsiface.SQSAPI, name string) *Queue {
	q, err := New(s, name)
	if err != nil {
		panic(err)
	}
	return q
}
func (q *Queue) ChangeMessageVisibility(receiptHandle *string, visibilityTimeout int64) error {
	req := &sqs.ChangeMessageVisibilityInput{
		ReceiptHandle:     receiptHandle,
		VisibilityTimeout: aws.Int64(visibilityTimeout),
		QueueUrl:          q.URL,
	}
	_, err := q.SQS.ChangeMessageVisibility(req)
	return err
}
type BatchChangeMessageVisibility struct {
	ReceiptHandle     *string
	VisibilityTimeout int64
}
func (q *Queue) ChangeMessageVisibilityBatch(opts ...BatchChangeMessageVisibility) error {
	entries := make([]*sqs.ChangeMessageVisibilityBatchRequestEntry, len(opts))
	id2index := make(map[string]int)
	for i, b := range opts {
		id := aws.String(fmt.Sprintf("msg-%d", i))
		entries[i] = &sqs.ChangeMessageVisibilityBatchRequestEntry{
			Id:                id,
			ReceiptHandle:     b.ReceiptHandle,
			VisibilityTimeout: aws.Int64(b.VisibilityTimeout),
		}
		id2index[*id] = i
	}
	req := &sqs.ChangeMessageVisibilityBatchInput{
		Entries:  entries,
		QueueUrl: q.URL,
	}
	resp, err := q.SQS.ChangeMessageVisibilityBatch(req)
	if err != nil {
		return err
	}
	return NewBatchError(id2index, resp.Failed)
}
func (q *Queue) SendMessage(body string, opts ...option.SendMessageInput) (*sqs.SendMessageOutput, error) {
	req := &sqs.SendMessageInput{
		MessageBody: aws.String(body),
		QueueUrl:    q.URL,
	}
	for _, f := range opts {
		f(req)
	}
	return q.SQS.SendMessage(req)
}
type BatchMessage struct {
	Body    string
	Options []option.SendMessageInput
}
type BatchError struct {
	Index       int
	Code        string
	Message     string
	SenderFault bool
}
func NewBatchError(id2index map[string]int, errors []*sqs.BatchResultErrorEntry) error {
	var result error
	for _, entry := range errors {
		err := &BatchError{
			Index:       id2index[*entry.Id],
			Code:        *entry.Code,
			Message:     *entry.Message,
			SenderFault: *entry.SenderFault,
		}
		result = multierror.Append(result, err)
	}
	return result
}
func (e *BatchError) Error() string {
	return fmt.Sprintf("sqs: index: %d, code: %s, is_sender_fault: %v: message: %s",
		e.Index,
		e.Code,
		e.SenderFault,
		e.Message,
	)
}
func IsBatchError(err error) (errors []*BatchError, ok bool) {
	merr, mok := err.(*multierror.Error)
	if !mok {
		return nil, false
	}
	for _, e := range merr.Errors {
		berr, ok := e.(*BatchError)
		if ok {
			errors = append(errors, berr)
		}
	}
	return errors, len(errors) > 0
}
func (q *Queue) SendMessageBatch(messages ...BatchMessage) error {
	entries, id2index := BuildBatchRequestEntry(messages...)
	req := &sqs.SendMessageBatchInput{
		Entries:  entries,
		QueueUrl: q.URL,
	}
	resp, err := q.SQS.SendMessageBatch(req)
	if err != nil {
		return err
	}
	return NewBatchError(id2index, resp.Failed)
}
func (q *Queue) ReceiveMessage(opts ...option.ReceiveMessageInput) ([]*sqs.Message, error) {
	req := &sqs.ReceiveMessageInput{
		QueueUrl: q.URL,
	}
	for _, f := range opts {
		f(req)
	}
	resp, err := q.SQS.ReceiveMessage(req)
	if err != nil {
		return nil, err
	}
	return resp.Messages, nil
}
func (q *Queue) DeleteMessage(receiptHandle *string) error {
	_, err := q.SQS.DeleteMessage(&sqs.DeleteMessageInput{
		QueueUrl:      q.URL,
		ReceiptHandle: receiptHandle,
	})
	return err
}