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

package s3

import (
	"context"
	"fmt"
	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
	"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"
	smithyhttp "github.com/aws/smithy-go/transport/http"
	"io"
	"time"
)

// Retrieves an annotation from an Amazon S3 object. To use this operation, you
// must have the s3:GetObjectAnnotation permission.
//
// If checksum mode is enabled via the x-amz-checksum-mode header, Amazon S3
// returns the stored checksum in the response headers for client-side validation.
//
// 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 GetObjectAnnotation :
//
// [PutObjectAnnotation]
//
// [ListObjectAnnotations]
//
// [DeleteObjectAnnotation]
//
// [DeleteObjectAnnotation]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjectAnnotation.html
// [ListObjectAnnotations]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectAnnotations.html
// [PutObjectAnnotation]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectAnnotation.html
func (c *Client) GetObjectAnnotation(ctx context.Context, params *GetObjectAnnotationInput, optFns ...func(*Options)) (*GetObjectAnnotationOutput, error) {
	if params == nil {
		params = &GetObjectAnnotationInput{}
	}

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

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

type GetObjectAnnotationInput struct {

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

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

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

	// Set to ENABLED to validate the checksum of the annotation payload on retrieval.
	ChecksumMode types.ChecksumMode

	// 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

	// 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.
	VersionId *string

	noSmithyDocumentSerde
}

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

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

}

type GetObjectAnnotationOutput struct {

	// The annotation payload.
	AnnotationPayload io.ReadCloser

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

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

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

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

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

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

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

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

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

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

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

	// The size of the annotation payload, in bytes.
	ContentLength *int64

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

	// The date and time the annotation was last modified.
	LastModified *time.Time

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

	// The replication status of the annotation. Possible values include PENDING ,
	// COMPLETED , FAILED , and REPLICA .
	ReplicationStatus types.ReplicationStatus

	// 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.
	ServerSideEncryption types.ServerSideEncryption

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationGetObjectAnnotationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
		return err
	}
	err = stack.Serialize.Add(&awsRestxml_serializeOpGetObjectAnnotation{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestxml_deserializeOpGetObjectAnnotation{}, middleware.After)
	if err != nil {
		return err
	}
	if err := addProtocolFinalizerMiddlewares(stack, options, "GetObjectAnnotation"); 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, c); 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 = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
		return err
	}
	if err = addPutBucketContextMiddleware(stack); err != nil {
		return err
	}
	if err = addUserAgentRetryMode(stack, options); err != nil {
		return err
	}
	if err = addIsExpressUserAgent(stack); err != nil {
		return err
	}
	if err = addResponseChecksumMetricsTracking(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpGetObjectAnnotationValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetObjectAnnotation(options.Region), middleware.Before); err != nil {
		return err
	}
	if err = addMetadataRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addRecursionDetection(stack); err != nil {
		return err
	}
	if err = addGetObjectAnnotationOutputChecksumMiddlewares(stack, options); err != nil {
		return err
	}
	if err = addGetObjectAnnotationUpdateEndpoint(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 = disableAcceptEncodingGzip(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 = 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 (v *GetObjectAnnotationInput) bucket() (string, bool) {
	if v.Bucket == nil {
		return "", false
	}
	return *v.Bucket, true
}

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

// getGetObjectAnnotationRequestValidationModeMember gets the request checksum
// validation mode provided as input.
func getGetObjectAnnotationRequestValidationModeMember(input interface{}) (string, bool) {
	in := input.(*GetObjectAnnotationInput)
	if len(in.ChecksumMode) == 0 {
		return "", false
	}
	return string(in.ChecksumMode), true
}

func setGetObjectAnnotationRequestValidationModeMember(input interface{}, mode string) {
	in := input.(*GetObjectAnnotationInput)
	in.ChecksumMode = types.ChecksumMode(mode)
}

func addGetObjectAnnotationOutputChecksumMiddlewares(stack *middleware.Stack, options Options) error {
	return internalChecksum.AddOutputMiddleware(stack, internalChecksum.OutputMiddlewareOptions{
		GetValidationMode:             getGetObjectAnnotationRequestValidationModeMember,
		SetValidationMode:             setGetObjectAnnotationRequestValidationModeMember,
		ResponseChecksumValidation:    options.ResponseChecksumValidation,
		ValidationAlgorithms:          []string{"CRC64NVME", "CRC32", "CRC32C", "SHA256", "SHA1", "SHA512", "MD5", "XXHASH64", "XXHASH3", "XXHASH128"},
		IgnoreMultipartValidation:     false,
		LogValidationSkipped:          !options.DisableLogOutputChecksumValidationSkipped,
		LogMultipartValidationSkipped: !options.DisableLogOutputChecksumValidationSkipped,
	})
}

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