// 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"
	"github.com/aws/smithy-go/ptr"
)

// Updates the annotation table configuration for an Amazon S3 bucket's metadata
// configuration. Use this operation to enable or disable the annotation table, or
// to update its associated IAM role.
//
// An annotation table is a queryable Iceberg table that contains records of all
// annotations attached to objects in the bucket. To use this operation, the bucket
// must have an existing Amazon S3 Metadata configuration.
//
// To use this operation, you must have the
// s3:UpdateBucketMetadataAnnotationTableConfiguration permission. If you are
// specifying or changing the IAM role, you must also have iam:PassRole permission
// for the role.
//
// The IAM role must have a trust policy that allows the Amazon S3 metadata
// service to assume it, and a permissions policy that grants the actions needed to
// read annotations from your bucket. The following examples show a trust policy
// and a permissions policy that you can adapt for your bucket and account.
//
// The following operations are related to
// UpdateBucketMetadataAnnotationTableConfiguration :
//
// [CreateBucketMetadataConfiguration]
//
// [GetBucketMetadataConfiguration]
//
// [GetBucketMetadataConfiguration]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketMetadataConfiguration.html
// [CreateBucketMetadataConfiguration]: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucketMetadataConfiguration.html
func (c *Client) UpdateBucketMetadataAnnotationTableConfiguration(ctx context.Context, params *UpdateBucketMetadataAnnotationTableConfigurationInput, optFns ...func(*Options)) (*UpdateBucketMetadataAnnotationTableConfigurationOutput, error) {
	if params == nil {
		params = &UpdateBucketMetadataAnnotationTableConfigurationInput{}
	}

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

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

type UpdateBucketMetadataAnnotationTableConfigurationInput struct {

	// The annotation table configuration updates to apply.
	//
	// This member is required.
	AnnotationTableConfiguration *types.AnnotationTableConfigurationUpdates

	// The name of the bucket whose annotation table configuration to update.
	//
	// This member is required.
	Bucket *string

	// Checksum algorithm for the request payload.
	ChecksumAlgorithm types.ChecksumAlgorithm

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

	// The account ID of the expected bucket owner.
	ExpectedBucketOwner *string

	noSmithyDocumentSerde
}

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

	p.Bucket = in.Bucket
	p.UseS3ExpressControlEndpoint = ptr.Bool(true)
}

type UpdateBucketMetadataAnnotationTableConfigurationOutput struct {
	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationUpdateBucketMetadataAnnotationTableConfigurationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestxml_serializeOpUpdateBucketMetadataAnnotationTableConfiguration{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestxml_deserializeOpUpdateBucketMetadataAnnotationTableConfiguration{}, 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 = addOpUpdateBucketMetadataAnnotationTableConfigurationValidationMiddleware(stack); err != nil {
		return err
	}
	if err = addMetadataRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addUpdateBucketMetadataAnnotationTableConfigurationInputChecksumMiddlewares(stack, options); err != nil {
		return err
	}
	if err = addUpdateBucketMetadataAnnotationTableConfigurationUpdateEndpoint(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 = 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 = s3cust.AddExpressDefaultChecksumMiddleware(stack); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

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

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

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

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