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

package braket

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

// Creates an Amazon Braket hybrid job.
func (c *Client) CreateJob(ctx context.Context, params *CreateJobInput, optFns ...func(*Options)) (*CreateJobOutput, error) {
	if params == nil {
		params = &CreateJobInput{}
	}

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

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

type CreateJobInput struct {

	// Definition of the Amazon Braket job to be created. Specifies the container
	// image the job uses and information about the Python scripts used for entry and
	// training.
	//
	// This member is required.
	AlgorithmSpecification *types.AlgorithmSpecification

	// The client token associated with this request that guarantees that the request
	// is idempotent.
	//
	// This member is required.
	ClientToken *string

	// The quantum processing unit (QPU) or simulator used to create an Amazon Braket
	// hybrid job.
	//
	// This member is required.
	DeviceConfig *types.DeviceConfig

	// Configuration of the resource instances to use while running the hybrid job on
	// Amazon Braket.
	//
	// This member is required.
	InstanceConfig *types.InstanceConfig

	// The name of the Amazon Braket hybrid job.
	//
	// This member is required.
	JobName *string

	// The path to the S3 location where you want to store hybrid job artifacts and
	// the encryption key used to store them.
	//
	// This member is required.
	OutputDataConfig *types.JobOutputDataConfig

	// The Amazon Resource Name (ARN) of an IAM role that Amazon Braket can assume to
	// perform tasks on behalf of a user. It can access user resources, run an Amazon
	// Braket job container on behalf of user, and output results and hybrid job
	// details to the users' s3 buckets.
	//
	// This member is required.
	RoleArn *string

	// The list of Amazon Braket resources associated with the hybrid job.
	Associations []types.Association

	// Information about the output locations for hybrid job checkpoint data.
	CheckpointConfig *types.JobCheckpointConfig

	// Algorithm-specific parameters used by an Amazon Braket hybrid job that
	// influence the quality of the training job. The values are set with a map of JSON
	// key:value pairs, where the key is the name of the hyperparameter and the value
	// is the value of the hyperparameter.
	//
	// Do not include any security-sensitive information including account access IDs,
	// secrets, or tokens in any hyperparameter fields. As part of the shared
	// responsibility model, you are responsible for any potential exposure,
	// unauthorized access, or compromise of your sensitive data if caused by
	// security-sensitive information included in the request hyperparameter variable
	// or plain text fields.
	HyperParameters map[string]string

	// A list of parameters that specify the name and type of input data and where it
	// is located.
	InputDataConfig []types.InputFileConfig

	//  The user-defined criteria that specifies when a hybrid job stops running.
	StoppingCondition *types.JobStoppingCondition

	// Tags to be added to the hybrid job you're creating.
	Tags map[string]string

	noSmithyDocumentSerde
}

type CreateJobOutput struct {

	// The ARN of the Amazon Braket hybrid job created.
	//
	// This member is required.
	JobArn *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateJobMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateJob{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateJob{}, 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_opCreateJobMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateJobValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateJob"), 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_initializeOpCreateJob struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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