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

package controltower

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

//	Updates the configuration of an already enabled control.
//
// If the enabled control shows an EnablementStatus of SUCCEEDED, supply
// parameters that are different from the currently configured parameters.
// Otherwise, Amazon Web Services Control Tower will not accept the request.
//
// If the enabled control shows an EnablementStatus of FAILED, Amazon Web Services
// Control Tower updates the control to match any valid parameters that you supply.
//
// If the DriftSummary status for the control shows as DRIFTED , you cannot call
// this API. Instead, you can update the control by calling the ResetEnabledControl
// API. Alternatively, you can call DisableControl and then call EnableControl
// again. Also, you can run an extending governance operation to repair drift. For
// usage examples, see the [Controls Reference Guide].
//
// [Controls Reference Guide]: https://docs.aws.amazon.com/controltower/latest/controlreference/control-api-examples-short.html
func (c *Client) UpdateEnabledControl(ctx context.Context, params *UpdateEnabledControlInput, optFns ...func(*Options)) (*UpdateEnabledControlOutput, error) {
	if params == nil {
		params = &UpdateEnabledControlInput{}
	}

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

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

type UpdateEnabledControlInput struct {

	//  The ARN of the enabled control that will be updated.
	//
	// This member is required.
	EnabledControlIdentifier *string

	// A key/value pair, where Key is of type String and Value is of type Document .
	//
	// This member is required.
	Parameters []types.EnabledControlParameter

	noSmithyDocumentSerde
}

type UpdateEnabledControlOutput struct {

	//  The operation identifier for this UpdateEnabledControl operation.
	//
	// This member is required.
	OperationIdentifier *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationUpdateEnabledControlMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpUpdateEnabledControl{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpUpdateEnabledControl{}, 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 = addOpUpdateEnabledControlValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "UpdateEnabledControl"), 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
}
