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

package datazone

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

// Updates a [notebook] in Amazon SageMaker Unified Studio.
//
// [notebook]: https://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/notebooks.html
func (c *Client) UpdateNotebook(ctx context.Context, params *UpdateNotebookInput, optFns ...func(*Options)) (*UpdateNotebookOutput, error) {
	if params == nil {
		params = &UpdateNotebookInput{}
	}

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

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

type UpdateNotebookInput struct {

	// The identifier of the Amazon SageMaker Unified Studio domain in which the
	// notebook exists.
	//
	// This member is required.
	DomainIdentifier *string

	// The identifier of the notebook to update.
	//
	// This member is required.
	Identifier *string

	// The updated ordered list of cells in the notebook.
	CellOrder []types.CellInformation

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

	// The updated description of the notebook.
	Description *string

	// The updated environment configuration for the notebook.
	EnvironmentConfiguration *types.EnvironmentConfig

	// The updated metadata for the notebook, specified as key-value pairs.
	Metadata map[string]string

	// The updated name of the notebook.
	Name *string

	// The updated sensitive parameters for the notebook, specified as key-value pairs.
	Parameters map[string]string

	// The updated status of the notebook.
	Status types.NotebookStatus

	noSmithyDocumentSerde
}

type UpdateNotebookOutput struct {

	// The ordered list of cells in the notebook.
	//
	// This member is required.
	CellOrder []types.CellInformation

	// The identifier of the Amazon SageMaker Unified Studio domain.
	//
	// This member is required.
	DomainId *string

	// The identifier of the notebook.
	//
	// This member is required.
	Id *string

	// The name of the notebook.
	//
	// This member is required.
	Name *string

	// The identifier of the project that owns the notebook.
	//
	// This member is required.
	OwningProjectId *string

	// The status of the notebook.
	//
	// This member is required.
	Status types.NotebookStatus

	// The identifier of the compute associated with the notebook.
	ComputeId *string

	// The timestamp of when the notebook was created.
	CreatedAt *time.Time

	// The identifier of the user who created the notebook.
	CreatedBy *string

	// The description of the notebook.
	Description *string

	// The environment configuration of the notebook.
	EnvironmentConfiguration *types.EnvironmentConfig

	// The error details if the notebook is in a failed state.
	Error *types.NotebookError

	// The timestamp of when the notebook lock expires.
	LockExpiresAt *time.Time

	// The timestamp of when the notebook was locked.
	LockedAt *time.Time

	// The identifier of the user who locked the notebook.
	LockedBy *string

	// The metadata of the notebook.
	Metadata map[string]string

	// The sensitive parameters of the notebook.
	Parameters map[string]string

	// The timestamp of when the notebook was last updated.
	UpdatedAt *time.Time

	// The identifier of the user who last updated the notebook.
	UpdatedBy *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationUpdateNotebookMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpUpdateNotebook{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpUpdateNotebook{}, 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_opUpdateNotebookMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpUpdateNotebookValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "UpdateNotebook"), 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_initializeOpUpdateNotebook struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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