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

import (
	"context"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/messaging"
	"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/messaging/eventgrid/aznamespaces/internal"
)

// SenderClientOptions contains the optional parameters when creating a SenderClient.
type SenderClientOptions struct {
	azcore.ClientOptions
}

// NewSenderClient creates a [SenderClient] which uses an azcore.TokenCredential for authentication.
func NewSenderClient(endpoint string, topic string, cred azcore.TokenCredential, options *SenderClientOptions) (*SenderClient, error) {
	if options == nil {
		options = &SenderClientOptions{}
	}

	azc, err := azcore.NewClient(internal.ModuleName+".Client", internal.ModuleVersion, runtime.PipelineOptions{
		PerRetry: []policy.Policy{
			runtime.NewBearerTokenPolicy(cred, []string{authScope}, nil),
		},
	}, &options.ClientOptions)

	if err != nil {
		return nil, err
	}

	return &SenderClient{
		internal: azc,
		endpoint: endpoint,
		data: senderData{
			Topic: topic,
		},
	}, nil
}

// NewSenderClientWithSharedKeyCredential creates a [SenderClient] using a shared key.
func NewSenderClientWithSharedKeyCredential(endpoint string, topic string, keyCred *azcore.KeyCredential, options *SenderClientOptions) (*SenderClient, error) {
	if options == nil {
		options = &SenderClientOptions{}
	}

	azc, err := azcore.NewClient(internal.ModuleName+".Client", internal.ModuleVersion, runtime.PipelineOptions{
		PerRetry: []policy.Policy{
			runtime.NewKeyCredentialPolicy(keyCred, "Authorization", &runtime.KeyCredentialPolicyOptions{
				Prefix: "SharedAccessKey ",
			}),
		},
	}, &options.ClientOptions)

	if err != nil {
		return nil, err
	}

	return &SenderClient{
		internal: azc,
		endpoint: endpoint,
		data: senderData{
			Topic: topic,
		},
	}, nil
}

type senderData struct {
	Topic string
}

// SendEvent publishes a single Cloud Event to a namespace topic.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-06-01
//   - event - Cloud Event to publish.
//   - options - SendOptions contains the optional parameters for the SenderClient.SendEvent method.
func (client *SenderClient) SendEvent(ctx context.Context, event *messaging.CloudEvent, options *SendEventOptions) (SendEventResponse, error) {
	return client.internalSendEvent(ctx, client.data.Topic, event, options)
}

// SendEvents publishes a batch of Cloud Events to a namespace topic.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2024-06-01
//   - events - slice of Cloud Events to publish.
//   - options - SendEventsOptions contains the optional parameters for the SenderClient.SendEvents method.
func (client *SenderClient) SendEvents(ctx context.Context, events []*messaging.CloudEvent, options *SendEventsOptions) (SendEventsResponse, error) {
	return client.internalSendEvents(ctx, client.data.Topic, events, options)
}
