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

package comprehend

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

// Starts an asynchronous event detection job for a collection of documents.
func (c *Client) StartEventsDetectionJob(ctx context.Context, params *StartEventsDetectionJobInput, optFns ...func(*Options)) (*StartEventsDetectionJobOutput, error) {
	if params == nil {
		params = &StartEventsDetectionJobInput{}
	}

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

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

type StartEventsDetectionJobInput struct {

	// The Amazon Resource Name (ARN) of the IAM role that grants Amazon Comprehend
	// read access to your input data.
	//
	// This member is required.
	DataAccessRoleArn *string

	// Specifies the format and location of the input data for the job.
	//
	// This member is required.
	InputDataConfig *types.InputDataConfig

	// The language code of the input documents.
	//
	// This member is required.
	LanguageCode types.LanguageCode

	// Specifies where to send the output files.
	//
	// This member is required.
	OutputDataConfig *types.OutputDataConfig

	// The types of events to detect in the input documents.
	//
	// This member is required.
	TargetEventTypes []string

	// An unique identifier for the request. If you don't set the client request
	// token, Amazon Comprehend generates one.
	ClientRequestToken *string

	// The identifier of the events detection job.
	JobName *string

	// Tags to associate with the events detection job. A tag is a key-value pair that
	// adds metadata to a resource used by Amazon Comprehend. For example, a tag with
	// "Sales" as the key might be added to a resource to indicate its use by the sales
	// department.
	Tags []types.Tag

	noSmithyDocumentSerde
}

type StartEventsDetectionJobOutput struct {

	// The Amazon Resource Name (ARN) of the events detection job. It is a unique,
	// fully qualified identifier for the job. It includes the Amazon Web Services
	// account, Amazon Web Services Region, and the job ID. The format of the ARN is as
	// follows:
	//
	//     arn::comprehend:::events-detection-job/
	//
	// The following is an example job ARN:
	//
	//     arn:aws:comprehend:us-west-2:111122223333:events-detection-job/1234abcd12ab34cd56ef1234567890ab
	JobArn *string

	// An unique identifier for the request. If you don't set the client request
	// token, Amazon Comprehend generates one.
	JobId *string

	// The status of the events detection job.
	JobStatus types.JobStatus

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationStartEventsDetectionJobMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson11_serializeOpStartEventsDetectionJob{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpStartEventsDetectionJob{}, 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_opStartEventsDetectionJobMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpStartEventsDetectionJobValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "StartEventsDetectionJob"), 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_initializeOpStartEventsDetectionJob struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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