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

package appstream

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

// Creates a new image with the latest Windows operating system updates, driver
// updates, and WorkSpaces Applications agent software.
//
// For more information, see the "Update an Image by Using Managed WorkSpaces
// Applications Image Updates" section in [Administer Your WorkSpaces Applications Images], in the Amazon WorkSpaces Applications
// Administration Guide.
//
// [Administer Your WorkSpaces Applications Images]: https://docs.aws.amazon.com/appstream2/latest/developerguide/administer-images.html
func (c *Client) CreateUpdatedImage(ctx context.Context, params *CreateUpdatedImageInput, optFns ...func(*Options)) (*CreateUpdatedImageOutput, error) {
	if params == nil {
		params = &CreateUpdatedImageInput{}
	}

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

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

type CreateUpdatedImageInput struct {

	// The name of the image to update.
	//
	// This member is required.
	ExistingImageName *string

	// The name of the new image. The name must be unique within the AWS account and
	// Region.
	//
	// This member is required.
	NewImageName *string

	// Indicates whether to display the status of image update availability before
	// WorkSpaces Applications initiates the process of creating a new updated image.
	// If this value is set to true , WorkSpaces Applications displays whether image
	// updates are available. If this value is set to false , WorkSpaces Applications
	// initiates the process of creating a new updated image without displaying whether
	// image updates are available.
	DryRun *bool

	// The description to display for the new image.
	NewImageDescription *string

	// The name to display for the new image.
	NewImageDisplayName *string

	// The tags to associate with the new image. A tag is a key-value pair, and the
	// value is optional. For example, Environment=Test. If you do not specify a value,
	// Environment=.
	//
	// Generally allowed characters are: letters, numbers, and spaces representable in
	// UTF-8, and the following special characters:
	//
	// _ . : / = + \ - @
	//
	// If you do not specify a value, the value is set to an empty string.
	//
	// For more information about tags, see [Tagging Your Resources] in the Amazon WorkSpaces Applications
	// Administration Guide.
	//
	// [Tagging Your Resources]: https://docs.aws.amazon.com/appstream2/latest/developerguide/tagging-basic.html
	NewImageTags map[string]string

	noSmithyDocumentSerde
}

type CreateUpdatedImageOutput struct {

	// Indicates whether a new image can be created.
	CanUpdateImage *bool

	// Describes an image.
	Image *types.Image

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateUpdatedImageMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
		return err
	}
	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateUpdatedImage{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateUpdatedImage{}, middleware.After)
	if err != nil {
		return err
	}
	if err := addProtocolFinalizerMiddlewares(stack, options, "CreateUpdatedImage"); err != nil {
		return fmt.Errorf("add protocol finalizers: %v", err)
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addSetLoggerMiddleware(stack, options); err != nil {
		return err
	}
	if err = addClientRequestID(stack); 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 = addRetry(stack, options); err != nil {
		return err
	}
	if err = addRawResponseToMetadata(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = addSpanRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addClientUserAgent(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 = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
		return err
	}
	if err = addTimeOffsetBuild(stack, c); err != nil {
		return err
	}
	if err = addUserAgentRetryMode(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpCreateUpdatedImageValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateUpdatedImage(options.Region), middleware.Before); err != nil {
		return err
	}
	if err = addRecursionDetection(stack); 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 = addInterceptBeforeRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addInterceptAttempt(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

func newServiceMetadataMiddleware_opCreateUpdatedImage(region string) *awsmiddleware.RegisterServiceMetadata {
	return &awsmiddleware.RegisterServiceMetadata{
		Region:        region,
		ServiceID:     ServiceID,
		OperationName: "CreateUpdatedImage",
	}
}
