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

package datazone

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

// Creates data export configuration details.
//
// If you want to temporarily disable export and later re-enable it for the same
// domain, use the --no-enable-export flag to disable and the --enable-export flag
// to re-enable. This preserves the configuration and allows you to re-enable
// export without deleting S3 table.
//
// You can enable asset metadata export for only one domain per account per
// Region. To enable export for a different domain, complete the following steps:
//
//   - Delete the export configuration for the currently enabled domain using the
//     DeleteDataExportConfiguration operation.
//
//   - Delete the asset S3 table under the aws-sagemaker-catalog S3 table bucket.
//     We recommend backing up the S3 table before deletion.
//
//   - Call the PutDataExportConfiguration API to enable export for the new domain.
func (c *Client) PutDataExportConfiguration(ctx context.Context, params *PutDataExportConfigurationInput, optFns ...func(*Options)) (*PutDataExportConfigurationOutput, error) {
	if params == nil {
		params = &PutDataExportConfigurationInput{}
	}

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

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

type PutDataExportConfigurationInput struct {

	// The domain ID for which you want to create data export configuration details.
	//
	// This member is required.
	DomainIdentifier *string

	// Specifies that the export is to be enabled as part of creating data export
	// configuration details.
	//
	// This member is required.
	EnableExport *bool

	// A unique, case-sensitive identifier to ensure idempotency of the request. This
	// field is automatically populated if not provided.
	ClientToken *string

	// The encryption configuration as part of creating data export configuration
	// details.
	//
	// The KMS key provided here as part of encryptionConfiguration must have the
	// required permissions as described in [KMS permissions for exporting asset metadata in Amazon SageMaker Unified Studio].
	//
	// [KMS permissions for exporting asset metadata in Amazon SageMaker Unified Studio]: https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/sagemaker-unified-studio-export-asset-metadata-kms-permissions.html
	EncryptionConfiguration *types.EncryptionConfiguration

	noSmithyDocumentSerde
}

type PutDataExportConfigurationOutput struct {
	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationPutDataExportConfigurationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
		return err
	}
	err = stack.Serialize.Add(&awsRestjson1_serializeOpPutDataExportConfiguration{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpPutDataExportConfiguration{}, middleware.After)
	if err != nil {
		return err
	}
	if err := addProtocolFinalizerMiddlewares(stack, options, "PutDataExportConfiguration"); 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_opPutDataExportConfigurationMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpPutDataExportConfigurationValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutDataExportConfiguration(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_initializeOpPutDataExportConfiguration struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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

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