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

package bedrockagentcore

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

// Creates an event in an AgentCore Memory resource. Events represent interactions
// or activities that occur within a session and are associated with specific
// actors.
//
// To use this operation, you must have the bedrock-agentcore:CreateEvent
// permission.
//
// This operation is subject to request rate limiting.
func (c *Client) CreateEvent(ctx context.Context, params *CreateEventInput, optFns ...func(*Options)) (*CreateEventOutput, error) {
	if params == nil {
		params = &CreateEventInput{}
	}

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

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

type CreateEventInput struct {

	// The identifier of the actor associated with this event. An actor represents an
	// entity that participates in sessions and generates events.
	//
	// This member is required.
	ActorId *string

	// The timestamp when the event occurred. If not specified, the current time is
	// used.
	//
	// This member is required.
	EventTimestamp *time.Time

	// The identifier of the AgentCore Memory resource in which to create the event.
	//
	// This member is required.
	MemoryId *string

	// The content payload of the event. This can include conversational data or
	// binary content.
	//
	// This member is required.
	Payload []types.PayloadType

	// The branch information for this event. Branches allow for organizing events
	// into different conversation threads or paths.
	Branch *types.Branch

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

	// Controls long-term memory extraction for this event. When set to SKIP , the
	// event is stored in short-term memory but is excluded from long-term memory
	// extraction. If not specified, the event is processed for extraction as usual.
	ExtractionMode types.ExtractionMode

	// The key-value metadata to attach to the event.
	Metadata map[string]types.MetadataValue

	// The identifier of the session in which this event occurs. A session represents
	// a sequence of related events.
	SessionId *string

	noSmithyDocumentSerde
}

type CreateEventOutput struct {

	// The event that was created.
	//
	// This member is required.
	Event *types.Event

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateEventMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateEvent{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateEvent{}, 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); 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_opCreateEventMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateEventValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateEvent"), 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_initializeOpCreateEvent struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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