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

package bedrockagentcore

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

// Saves the current state of a browser session as a reusable profile in Amazon
// Bedrock AgentCore. A browser profile captures persistent browser data such as
// cookies and local storage from an active session, enabling you to reuse this
// data in future browser sessions.
//
// To save a browser session profile, you must specify the profile identifier,
// browser identifier, and session ID. The session must be active when saving the
// profile. Once saved, the profile can be used with the StartBrowserSession
// operation to initialize new sessions with the stored browser state.
//
// Browser profiles are useful for scenarios that require persistent
// authentication, maintaining user preferences across sessions, or continuing
// tasks that depend on previously stored browser data.
//
// The following operations are related to SaveBrowserSessionProfile :
//
// [StartBrowserSession]
//
// [GetBrowserSession]
//
// [GetBrowserSession]: https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_GetBrowserSession.html
// [StartBrowserSession]: https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_StartBrowserSession.html
func (c *Client) SaveBrowserSessionProfile(ctx context.Context, params *SaveBrowserSessionProfileInput, optFns ...func(*Options)) (*SaveBrowserSessionProfileOutput, error) {
	if params == nil {
		params = &SaveBrowserSessionProfileInput{}
	}

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

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

type SaveBrowserSessionProfileInput struct {

	// The unique identifier of the browser associated with the session from which to
	// save the profile.
	//
	// This member is required.
	BrowserIdentifier *string

	// The unique identifier for the browser profile. This identifier is used to
	// reference the profile when starting new browser sessions. The identifier must
	// follow the pattern of an alphanumeric name (up to 48 characters) followed by a
	// hyphen and a 10-character alphanumeric suffix.
	//
	// This member is required.
	ProfileIdentifier *string

	// The unique identifier of the browser session from which to save the profile.
	// The session must be active when saving the profile.
	//
	// This member is required.
	SessionId *string

	// A unique, case-sensitive identifier to ensure that the API request completes no
	// more than one time. If this token matches a previous request, Amazon Bedrock
	// AgentCore ignores the request, but does not return an error.
	ClientToken *string

	// The trace identifier for request tracking.
	TraceId *string

	// The parent trace information for distributed tracing.
	TraceParent *string

	noSmithyDocumentSerde
}

type SaveBrowserSessionProfileOutput struct {

	// The unique identifier of the browser associated with the session from which the
	// profile was saved.
	//
	// This member is required.
	BrowserIdentifier *string

	// The timestamp when the browser profile was last updated. This value is in ISO
	// 8601 format.
	//
	// This member is required.
	LastUpdatedAt *time.Time

	// The unique identifier of the saved browser profile.
	//
	// This member is required.
	ProfileIdentifier *string

	// The unique identifier of the browser session from which the profile was saved.
	//
	// This member is required.
	SessionId *string

	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationSaveBrowserSessionProfileMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
		return err
	}
	err = stack.Serialize.Add(&awsRestjson1_serializeOpSaveBrowserSessionProfile{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSaveBrowserSessionProfile{}, middleware.After)
	if err != nil {
		return err
	}
	if err := addProtocolFinalizerMiddlewares(stack, options, "SaveBrowserSessionProfile"); err != nil {
		return fmt.Errorf("add protocol finalizers: %v", err)
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addSetLoggerMiddleware(stack, options); err != nil {
		return err
	}
	if err = addClientRequestID(stack); 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 = addRetry(stack, options); err != nil {
		return err
	}
	if err = addRawResponseToMetadata(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = addSpanRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addClientUserAgent(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 = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
		return err
	}
	if err = addTimeOffsetBuild(stack, c); err != nil {
		return err
	}
	if err = addUserAgentRetryMode(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addIdempotencyToken_opSaveBrowserSessionProfileMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpSaveBrowserSessionProfileValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSaveBrowserSessionProfile(options.Region), middleware.Before); err != nil {
		return err
	}
	if err = addRecursionDetection(stack); 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 = addInterceptBeforeRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addInterceptAttempt(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

type idempotencyToken_initializeOpSaveBrowserSessionProfile struct {
	tokenProvider IdempotencyTokenProvider
}

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

func (m *idempotencyToken_initializeOpSaveBrowserSessionProfile) 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.(*SaveBrowserSessionProfileInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *SaveBrowserSessionProfileInput ")
	}

	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_opSaveBrowserSessionProfileMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpSaveBrowserSessionProfile{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}

func newServiceMetadataMiddleware_opSaveBrowserSessionProfile(region string) *awsmiddleware.RegisterServiceMetadata {
	return &awsmiddleware.RegisterServiceMetadata{
		Region:        region,
		ServiceID:     ServiceID,
		OperationName: "SaveBrowserSessionProfile",
	}
}
