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

// Copies a model to another region so that it can be used there. For more
// information, see [Copy models to be used in other regions]in the [Amazon Bedrock User Guide].
//
// [Copy models to be used in other regions]: https://docs.aws.amazon.com/bedrock/latest/userguide/copy-model.html
// [Amazon Bedrock User Guide]: https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html
func (c *Client) CreateModelCopyJob(ctx context.Context, params *CreateModelCopyJobInput, optFns ...func(*Options)) (*CreateModelCopyJobOutput, error) {
	if params == nil {
		params = &CreateModelCopyJobInput{}
	}

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

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

type CreateModelCopyJobInput struct {

	// The Amazon Resource Name (ARN) of the model to be copied.
	//
	// This member is required.
	SourceModelArn *string

	// A name for the copied model.
	//
	// This member is required.
	TargetModelName *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
	// ignores the request, but does not return an error. For more information, see [Ensuring idempotency].
	//
	// [Ensuring idempotency]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html
	ClientRequestToken *string

	// The ARN of the KMS key that you use to encrypt the model copy.
	ModelKmsKeyId *string

	// Tags to associate with the target model. For more information, see [Tag resources] in the [Amazon Bedrock User Guide].
	//
	// [Tag resources]: https://docs.aws.amazon.com/bedrock/latest/userguide/tagging.html
	// [Amazon Bedrock User Guide]: https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html
	TargetModelTags []types.Tag

	noSmithyDocumentSerde
}

type CreateModelCopyJobOutput struct {

	// The Amazon Resource Name (ARN) of the model copy job.
	//
	// This member is required.
	JobArn *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateModelCopyJobMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateModelCopyJob{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateModelCopyJob{}, 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_opCreateModelCopyJobMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateModelCopyJobValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateModelCopyJob"), 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_initializeOpCreateModelCopyJob struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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