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

package b2bi

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

// Runs a job, using a transformer, to parse input EDI (electronic data
// interchange) file into the output structures used by Amazon Web Services B2B
// Data Interchange.
//
// If you only want to transform EDI (electronic data interchange) documents, you
// don't need to create profiles, partnerships or capabilities. Just create and
// configure a transformer, and then run the StartTransformerJob API to process
// your files.
//
// The system stores transformer jobs for 30 days. During that period, you can run [GetTransformerJob]
// and supply its transformerId and transformerJobId to return details of the job.
//
// [GetTransformerJob]: https://docs.aws.amazon.com/b2bi/latest/APIReference/API_GetTransformerJob.html
func (c *Client) StartTransformerJob(ctx context.Context, params *StartTransformerJobInput, optFns ...func(*Options)) (*StartTransformerJobOutput, error) {
	if params == nil {
		params = &StartTransformerJobInput{}
	}

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

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

type StartTransformerJobInput struct {

	// Specifies the location of the input file for the transformation. The location
	// consists of an Amazon S3 bucket and prefix.
	//
	// This member is required.
	InputFile *types.S3Location

	// Specifies the location of the output file for the transformation. The location
	// consists of an Amazon S3 bucket and prefix.
	//
	// This member is required.
	OutputLocation *types.S3Location

	// Specifies the system-assigned unique identifier for the transformer.
	//
	// This member is required.
	TransformerId *string

	// Reserved for future use.
	ClientToken *string

	noSmithyDocumentSerde
}

type StartTransformerJobOutput struct {

	// Returns the unique, system-generated identifier for a transformer run.
	//
	// This member is required.
	TransformerJobId *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationStartTransformerJobMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson10_serializeOpStartTransformerJob{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpStartTransformerJob{}, 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_opStartTransformerJobMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpStartTransformerJobValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "StartTransformerJob"), 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_initializeOpStartTransformerJob struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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