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

package ec2

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/service/ec2/types"
	"github.com/aws/smithy-go/middleware"
)

// Disassociates an application status check from instances or [tags]. After
// disassociation, health monitoring stops for the affected instances. The
// following rules apply:
//
//   - You must specify either TargetTagAssociations or InstanceIds , but not both.
//     Specifying both results in an InvalidParameterCombination error.
//
//   - The application status check must already exist and belong to your account.
//
//   - Tag keys must not be blank.
//
// [tags]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html
func (c *Client) DisassociateApplicationStatusCheck(ctx context.Context, params *DisassociateApplicationStatusCheckInput, optFns ...func(*Options)) (*DisassociateApplicationStatusCheckOutput, error) {
	if params == nil {
		params = &DisassociateApplicationStatusCheckInput{}
	}

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

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

type DisassociateApplicationStatusCheckInput struct {

	// The ID of the application status check to disassociate.
	//
	// This member is required.
	ApplicationStatusCheckId *string

	// A unique, case-sensitive identifier that you provide to ensure that the
	// operation completes no more than one time. If you retry a request with the same
	// token, the service ignores the request but does not return an error. For more
	// information, see [Ensuring idempotency].
	//
	// [Ensuring idempotency]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html
	ClientToken *string

	// Checks whether you have the required permissions for the operation, without
	// actually making the request, and provides an error response. If you have the
	// required permissions, the error response is DryRunOperation . Otherwise, it is
	// UnauthorizedOperation .
	DryRun *bool

	// The IDs of the instances to disassociate from the application status check.
	InstanceIds []string

	// The [tags] to disassociate from the application status check. Specify the same
	// key-value pairs that were used during association.
	//
	// [tags]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html
	TargetTagAssociations []types.CustomTagKeyValueRequestPair

	noSmithyDocumentSerde
}

type DisassociateApplicationStatusCheckOutput struct {

	// The associations that were successfully removed.
	SuccessfulResults []types.SuccessfulAssociationResponseObject

	// The associations that failed to be removed.
	UnsuccessfulResults []types.UnsuccessfulAssociationResponseObject

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationDisassociateApplicationStatusCheckMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsEc2query_serializeOpDisassociateApplicationStatusCheck{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsEc2query_deserializeOpDisassociateApplicationStatusCheck{}, 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 = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addIdempotencyToken_opDisassociateApplicationStatusCheckMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpDisassociateApplicationStatusCheckValidationMiddleware(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 = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

type idempotencyToken_initializeOpDisassociateApplicationStatusCheck struct {
	tokenProvider IdempotencyTokenProvider
}

func (*idempotencyToken_initializeOpDisassociateApplicationStatusCheck) ID() string {
	return "OperationIdempotencyTokenAutoFill"
}

func (m *idempotencyToken_initializeOpDisassociateApplicationStatusCheck) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
	if m.tokenProvider == nil {
		return next.HandleInitialize(ctx, in)
	}

	input, ok := in.Parameters.(*DisassociateApplicationStatusCheckInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *DisassociateApplicationStatusCheckInput ")
	}

	if input.ClientToken == nil {
		t, err := m.tokenProvider.GetIdempotencyToken()
		if err != nil {
			return out, metadata, err
		}
		input.ClientToken = &t
	}
	return next.HandleInitialize(ctx, in)
}
func addIdempotencyToken_opDisassociateApplicationStatusCheckMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpDisassociateApplicationStatusCheck{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
