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

package bedrock

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

// Updates the configuration of an existing endpoint for a model from Amazon
// Bedrock Marketplace.
func (c *Client) UpdateMarketplaceModelEndpoint(ctx context.Context, params *UpdateMarketplaceModelEndpointInput, optFns ...func(*Options)) (*UpdateMarketplaceModelEndpointOutput, error) {
	if params == nil {
		params = &UpdateMarketplaceModelEndpointInput{}
	}

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

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

type UpdateMarketplaceModelEndpointInput struct {

	// The Amazon Resource Name (ARN) of the endpoint you want to update.
	//
	// This member is required.
	EndpointArn *string

	// The new configuration for the endpoint, including the number and type of
	// instances to use.
	//
	// This member is required.
	EndpointConfig types.EndpointConfig

	// A unique, case-sensitive identifier that you provide to ensure the idempotency
	// of the request. This token is listed as not required because Amazon Web Services
	// SDKs automatically generate it for you and set this parameter. If you're not
	// using the Amazon Web Services SDK or the CLI, you must provide this token or the
	// action will fail.
	ClientRequestToken *string

	noSmithyDocumentSerde
}

type UpdateMarketplaceModelEndpointOutput struct {

	// Details about the updated endpoint.
	//
	// This member is required.
	MarketplaceModelEndpoint *types.MarketplaceModelEndpoint

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationUpdateMarketplaceModelEndpointMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpUpdateMarketplaceModelEndpoint{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpUpdateMarketplaceModelEndpoint{}, 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_opUpdateMarketplaceModelEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpUpdateMarketplaceModelEndpointValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "UpdateMarketplaceModelEndpoint"), 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_initializeOpUpdateMarketplaceModelEndpoint struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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