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

package connect

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

// Creates an attached file for a completed voice contact by copying a recording
// from a source S3 URI into Connect Customer managed storage. Use this API to
// attach voice recordings to contacts for downstream processing such as
// conversational analytics.
//
// The AssociatedResourceArn must be the ARN of a completed voice contact,
// FileUseCaseType must be set to VOICE_RECORDING , and FileSourceUri must be a
// valid S3 URI.
//
// For example, you can call CreateContact , then CreateAttachedFile , then
// StartContactConversationalAnalyticsJob to create a contact, attach a recording,
// and run post-call analytics.
func (c *Client) CreateAttachedFile(ctx context.Context, params *CreateAttachedFileInput, optFns ...func(*Options)) (*CreateAttachedFileOutput, error) {
	if params == nil {
		params = &CreateAttachedFileInput{}
	}

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

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

type CreateAttachedFileInput struct {

	// The ARN of the completed voice contact to attach the file to. Only voice
	// contacts with Telephony subtype are supported.
	//
	// This value must be a valid ARN.
	//
	// This member is required.
	AssociatedResourceArn *string

	// The S3 URI of the file to be attached. Only S3 source URIs are supported.
	//
	// This member is required.
	FileSourceUri *string

	// The use case for the file.
	//
	// Only VOICE_RECORDING is supported.
	//
	// This member is required.
	FileUseCaseType types.FileUseCaseType

	// The identifier of the Connect Customer instance. You can [find the instance ID] in the Amazon
	// Resource Name (ARN) of the instance.
	//
	// [find the instance ID]: https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html
	//
	// This member is required.
	InstanceId *string

	// A unique, case-sensitive identifier that you provide to ensure the idempotency
	// of the request. If not provided, the Amazon Web Services SDK populates this
	// field. For more information about idempotency, see [Making retries safe with idempotent APIs].
	//
	// [Making retries safe with idempotent APIs]: https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/
	ClientToken *string

	// The tags used to organize, track, or control access for this resource. For
	// example, { "Tags": {"key1":"value1", "key2":"value2"} } .
	Tags map[string]string

	noSmithyDocumentSerde
}

// Response from CreateAttachedFile API.
type CreateAttachedFileOutput struct {

	// The time of Creation of the file resource as an ISO timestamp. It's specified
	// in ISO 8601 format: yyyy-MM-ddThh:mm:ss.SSSZ . For example,
	// 2024-05-03T02:41:28.172Z .
	CreationTime *string

	// The unique identifier of the attached file resource (ARN).
	FileArn *string

	// The unique identifier of the attached file resource.
	FileId *string

	// The current status of the attached file. Valid values: PROCESSING | APPROVED |
	// REJECTED | FAILED .
	FileStatus types.FileStatusType

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateAttachedFileMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateAttachedFile{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateAttachedFile{}, 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_opCreateAttachedFileMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateAttachedFileValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateAttachedFile"), 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_initializeOpCreateAttachedFile struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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