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

package s3

import (
	"context"
	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
	internalChecksum "github.com/aws/aws-sdk-go-v2/service/internal/checksum"
	s3cust "github.com/aws/aws-sdk-go-v2/service/s3/internal/customizations"
	"github.com/aws/aws-sdk-go-v2/service/s3/types"
	"github.com/aws/smithy-go/middleware"
	"io"
)

// Attaches an annotation to an Amazon S3 object. An annotation is a named payload
// of 1 byte to 1 MiB that you can associate with a specific object or object
// version. Each object can have up to 1,000 annotations.
//
// For annotation naming rules and restrictions, see [Annotation naming guidelines] in the Amazon S3 User Guide.
//
// Annotations inherit the encryption of their parent object. For objects without
// server-side encryption, annotations are encrypted with SSE-S3 (the default for
// new objects). Objects encrypted with SSE-C cannot have annotations.
//
// To use this operation, you must have the s3:PutObjectAnnotation permission. If
// the bucket has Requester Pays enabled, you must include the x-amz-request-payer
// header.
//
// Annotations are not supported by the following features: S3 Inventory Reports,
// API Gateway, S3 Storage Lens, Amazon S3 File Gateway, Amazon FSx, S3 on
// Outposts, and S3 Express One Zone (directory buckets).
//
// The following operations are related to PutObjectAnnotation :
//
// [GetObjectAnnotation]
//
// [ListObjectAnnotations]
//
// [DeleteObjectAnnotation]
//
// [GetObjectAnnotation]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAnnotation.html
// [DeleteObjectAnnotation]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjectAnnotation.html
// [Annotation naming guidelines]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/annotations-overview.html
// [ListObjectAnnotations]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectAnnotations.html
func (c *Client) PutObjectAnnotation(ctx context.Context, params *PutObjectAnnotationInput, optFns ...func(*Options)) (*PutObjectAnnotationOutput, error) {
	if params == nil {
		params = &PutObjectAnnotationInput{}
	}

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

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

type PutObjectAnnotationInput struct {

	// The name of the annotation.
	//
	// Length Constraints: Minimum length of 1. Maximum length of 512 bytes.
	//
	// This member is required.
	AnnotationName *string

	// The annotation payload. Must be between 1 byte and 1 MiB in size, and must be
	// valid UTF-8 encoded text. If the payload contains invalid UTF-8 bytes, the
	// request fails with HTTP 415 (Unsupported Media Type). To store binary data,
	// encode the payload using Base64 before uploading.
	//
	// This member is required.
	AnnotationPayload io.Reader

	// The name of the bucket that contains the object.
	//
	// This member is required.
	Bucket *string

	// The object key.
	//
	// This member is required.
	Key *string

	// The checksum algorithm to use. Supported values: CRC32 , CRC32C , CRC64NVME ,
	// SHA1 , SHA256 , SHA512 , MD5 , XXHASH64 , XXHASH3 , XXHASH128 .
	ChecksumAlgorithm types.ChecksumAlgorithm

	// Base64-encoded CRC32 checksum of the annotation payload.
	ChecksumCRC32 *string

	// Base64-encoded CRC32C checksum of the annotation payload.
	ChecksumCRC32C *string

	// Base64-encoded CRC64NVME checksum of the annotation payload.
	ChecksumCRC64NVME *string

	// Base64-encoded MD5 checksum of the annotation payload.
	ChecksumMD5 *string

	// Base64-encoded SHA1 checksum of the annotation payload.
	ChecksumSHA1 *string

	// Base64-encoded SHA256 checksum of the annotation payload.
	ChecksumSHA256 *string

	// Base64-encoded SHA512 checksum of the annotation payload.
	ChecksumSHA512 *string

	// Base64-encoded XXHASH128 checksum of the annotation payload.
	ChecksumXXHASH128 *string

	// Base64-encoded XXHASH3 checksum of the annotation payload.
	ChecksumXXHASH3 *string

	// Base64-encoded XXHASH64 checksum of the annotation payload.
	ChecksumXXHASH64 *string

	// Base64-encoded MD5 digest of the message.
	ContentMD5 *string

	// The account ID of the expected bucket owner. If the bucket is owned by a
	// different account, the request fails with an HTTP 403 (Access Denied) error.
	ExpectedBucketOwner *string

	// If specified, the operation only succeeds if the object's ETag matches the
	// provided value.
	ObjectIfMatch *string

	// Confirms that the requester knows that they will be charged for the request.
	// Bucket owners need not specify this parameter in their requests. If either the
	// source or destination S3 bucket has Requester Pays enabled, the requester will
	// pay for the corresponding charges. For information about downloading objects
	// from Requester Pays buckets, see [Downloading Objects in Requester Pays Buckets]in the Amazon S3 User Guide.
	//
	// This functionality is not supported for directory buckets.
	//
	// [Downloading Objects in Requester Pays Buckets]: https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
	RequestPayer types.RequestPayer

	// The version ID of the object to attach the annotation to.
	VersionId *string

	noSmithyDocumentSerde
}

func (in *PutObjectAnnotationInput) bindEndpointParams(p *EndpointParameters) {

	p.Bucket = in.Bucket
	p.Key = in.Key

}

type PutObjectAnnotationOutput struct {

	// The name of the annotation.
	AnnotationName *string

	// The CRC32 checksum of the stored annotation.
	ChecksumCRC32 *string

	// The CRC32C checksum of the stored annotation.
	ChecksumCRC32C *string

	// The CRC64NVME checksum of the stored annotation.
	ChecksumCRC64NVME *string

	// The MD5 checksum of the stored annotation.
	ChecksumMD5 *string

	// The SHA1 checksum of the stored annotation.
	ChecksumSHA1 *string

	// The SHA256 checksum of the stored annotation.
	ChecksumSHA256 *string

	// The SHA512 checksum of the stored annotation.
	ChecksumSHA512 *string

	// The type of checksum used.
	ChecksumType types.ChecksumType

	// The XXHASH128 checksum of the stored annotation.
	ChecksumXXHASH128 *string

	// The XXHASH3 checksum of the stored annotation.
	ChecksumXXHASH3 *string

	// The XXHASH64 checksum of the stored annotation.
	ChecksumXXHASH64 *string

	// The entity tag of the annotation.
	ETag *string

	// The object key.
	Key *string

	// The version ID of the object that the annotation was attached to.
	ObjectVersionId *string

	// If present, indicates that the requester was successfully charged for the
	// request. For more information, see [Using Requester Pays buckets for storage transfers and usage]in the Amazon Simple Storage Service user
	// guide.
	//
	// This functionality is not supported for directory buckets.
	//
	// [Using Requester Pays buckets for storage transfers and usage]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/RequesterPaysBuckets.html
	RequestCharged types.RequestCharged

	// The server-side encryption algorithm used to encrypt the annotation.
	ServerSideEncryption types.ServerSideEncryption

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationPutObjectAnnotationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestxml_serializeOpPutObjectAnnotation{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestxml_deserializeOpPutObjectAnnotation{}, middleware.After)
	if 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 = addPutBucketContextMiddleware(stack); err != nil {
		return err
	}
	if err = addIsExpressUserAgent(stack); err != nil {
		return err
	}
	if err = addRequestChecksumMetricsTracking(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpPutObjectAnnotationValidationMiddleware(stack); err != nil {
		return err
	}
	if err = addMetadataRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addPutObjectAnnotationInputChecksumMiddlewares(stack, options); err != nil {
		return err
	}
	if err = addPutObjectAnnotationUpdateEndpoint(stack, options); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
		return err
	}
	if err = v4.UseDynamicPayloadSigningMiddleware(stack); err != nil {
		return err
	}
	if err = disableAcceptEncodingGzip(stack); err != nil {
		return err
	}
	if err = s3cust.HandleResponseErrorWith200Status(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 = addSerializeImmutableHostnameBucketMiddleware(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

func (v *PutObjectAnnotationInput) bucket() (string, bool) {
	if v.Bucket == nil {
		return "", false
	}
	return *v.Bucket, true
}

// getPutObjectAnnotationRequestAlgorithmMember gets the request checksum
// algorithm value provided as input.
func getPutObjectAnnotationRequestAlgorithmMember(input interface{}) (string, bool) {
	in := input.(*PutObjectAnnotationInput)
	if len(in.ChecksumAlgorithm) == 0 {
		return "", false
	}
	return string(in.ChecksumAlgorithm), true
}

func addPutObjectAnnotationInputChecksumMiddlewares(stack *middleware.Stack, options Options) error {
	return addInputChecksumMiddleware(stack, internalChecksum.InputMiddlewareOptions{
		GetAlgorithm:                     getPutObjectAnnotationRequestAlgorithmMember,
		RequireChecksum:                  false,
		RequestChecksumCalculation:       options.RequestChecksumCalculation,
		EnableTrailingChecksum:           true,
		EnableComputeSHA256PayloadHash:   true,
		EnableDecodedContentLengthHeader: true,
	})
}

// getPutObjectAnnotationBucketMember returns a pointer to string denoting a
// provided bucket member valueand a boolean indicating if the input has a modeled
// bucket name,
func getPutObjectAnnotationBucketMember(input interface{}) (*string, bool) {
	in := input.(*PutObjectAnnotationInput)
	if in.Bucket == nil {
		return nil, false
	}
	return in.Bucket, true
}
func addPutObjectAnnotationUpdateEndpoint(stack *middleware.Stack, options Options) error {
	return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{
		Accessor: s3cust.UpdateEndpointParameterAccessor{
			GetBucketFromInput: getPutObjectAnnotationBucketMember,
		},
		UsePathStyle:                   options.UsePathStyle,
		UseAccelerate:                  options.UseAccelerate,
		SupportsAccelerate:             true,
		TargetS3ObjectLambda:           false,
		EndpointResolver:               options.EndpointResolver,
		EndpointResolverOptions:        options.EndpointOptions,
		UseARNRegion:                   options.UseARNRegion,
		DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints,
	})
}
