// 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"
)

// Updates an A/B test's configuration, including variants, traffic allocation,
// evaluation settings, or execution status.
func (c *Client) UpdateABTest(ctx context.Context, params *UpdateABTestInput, optFns ...func(*Options)) (*UpdateABTestOutput, error) {
	if params == nil {
		params = &UpdateABTestInput{}
	}

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

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

type UpdateABTestInput struct {

	// The unique identifier of the A/B test to update.
	//
	// This member is required.
	AbTestId *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, the service
	// ignores the request, but does not return an error.
	ClientToken *string

	// The updated description of the A/B test.
	Description *string

	// The updated evaluation configuration.
	EvaluationConfig types.ABTestEvaluationConfig

	// The updated execution status to enable or disable the A/B test.
	ExecutionStatus types.ABTestExecutionStatus

	// The updated gateway filter.
	GatewayFilter *types.GatewayFilter

	// The updated name of the A/B test.
	Name *string

	// The updated IAM role ARN.
	RoleArn *string

	// The updated list of variants.
	Variants []types.Variant

	noSmithyDocumentSerde
}

type UpdateABTestOutput struct {

	// The Amazon Resource Name (ARN) of the updated A/B test.
	//
	// This member is required.
	AbTestArn *string

	// The unique identifier of the updated A/B test.
	//
	// This member is required.
	AbTestId *string

	// The execution status of the A/B test.
	//
	// This member is required.
	ExecutionStatus types.ABTestExecutionStatus

	// The status of the A/B test.
	//
	// This member is required.
	Status types.ABTestStatus

	// The timestamp when the A/B test was updated.
	//
	// This member is required.
	UpdatedAt *time.Time

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationUpdateABTestMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpUpdateABTest{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpUpdateABTest{}, 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_opUpdateABTestMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpUpdateABTestValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "UpdateABTest"), 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_initializeOpUpdateABTest struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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