// Code generated by smithy-go-codegen DO NOT EDIT.

package connect

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/connect/types"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
	"time"
)

// Sends an outbound web notification to a customer's web browser for outbound
// campaigns. For more information about outbound campaigns, see [Set up Connect Customer outbound campaigns].
//
// Only the Connect Customer outbound campaigns service principal is allowed to
// assume a role in your account and call this API.
//
// [Set up Connect Customer outbound campaigns]: https://docs.aws.amazon.com/connect/latest/adminguide/enable-outbound-campaigns.html
func (c *Client) SendOutboundWebNotification(ctx context.Context, params *SendOutboundWebNotificationInput, optFns ...func(*Options)) (*SendOutboundWebNotificationOutput, error) {
	if params == nil {
		params = &SendOutboundWebNotificationInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "SendOutboundWebNotification", params, optFns, c.addOperationSendOutboundWebNotificationMiddlewares)
	if err != nil {
		return nil, err
	}

	out := result.(*SendOutboundWebNotificationOutput)
	out.ResultMetadata = metadata
	return out, nil
}

type SendOutboundWebNotificationInput struct {

	// A unique identifier for the customer's web browser instance to which the
	// notification is being sent.
	//
	// This member is required.
	BrowserId *string

	// The content of the web notification, including the notification type, the view
	// to render, and any optional attributes used to populate it.
	//
	// This member is required.
	Content *types.WebNotificationContent

	// The destination for the web notification, specifying the communication widget
	// that delivers the notification and the customer profile of the recipient.
	//
	// This member is required.
	Destination *types.WidgetDestination

	// The timestamp, in Unix epoch time format, at which the web notification
	// expires. After this time, the notification is no longer delivered to the
	// customer's browser.
	//
	// This member is required.
	ExpiresAt *time.Time

	// The identifier of the Connect Customer instance. You can [find the instance ID] in the Amazon
	// Resource Name (ARN) of the instance.
	//
	// [find the instance ID]: https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html
	//
	// This member is required.
	InstanceId *string

	// A unique identifier for the customer's web session to which the notification is
	// being sent.
	//
	// This member is required.
	SessionId *string

	// The source of the web notification. A SourceCampaign object identifies the
	// campaign and outbound request that triggered this notification.
	//
	// This member is required.
	Source *types.WebNotificationSource

	// A unique, case-sensitive identifier that you provide to ensure the idempotency
	// of the request. If not provided, the Amazon Web Services SDK populates this
	// field. For more information about idempotency, see [Making retries safe with idempotent APIs].
	//
	// [Making retries safe with idempotent APIs]: https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/
	ClientToken *string

	noSmithyDocumentSerde
}

type SendOutboundWebNotificationOutput struct {
	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationSendOutboundWebNotificationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpSendOutboundWebNotification{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSendOutboundWebNotification{}, middleware.After)
	if err != nil {
		return err
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addComputeContentLength(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = addComputePayloadSHA256(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack, options); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addIdempotencyToken_opSendOutboundWebNotificationMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpSendOutboundWebNotificationValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "SendOutboundWebNotification"), middleware.Before); err != nil {
		return err
	}
	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = addRequestResponseLogging(stack, options); err != nil {
		return err
	}
	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

type idempotencyToken_initializeOpSendOutboundWebNotification struct {
	tokenProvider IdempotencyTokenProvider
}

func (*idempotencyToken_initializeOpSendOutboundWebNotification) ID() string {
	return "OperationIdempotencyTokenAutoFill"
}

func (m *idempotencyToken_initializeOpSendOutboundWebNotification) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
	if m.tokenProvider == nil {
		return next.HandleInitialize(ctx, in)
	}

	input, ok := in.Parameters.(*SendOutboundWebNotificationInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *SendOutboundWebNotificationInput ")
	}

	if input.ClientToken == nil {
		t, err := m.tokenProvider.GetIdempotencyToken()
		if err != nil {
			return out, metadata, err
		}
		input.ClientToken = &t
	}
	return next.HandleInitialize(ctx, in)
}
func addIdempotencyToken_opSendOutboundWebNotificationMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpSendOutboundWebNotification{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
