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

// Modifies an existing application status check. You can update the protocol,
// port, path, thresholds, and other configuration settings. The following rules
// apply:
//
//   - The application status check must exist and belong to your account.
//
//   - Changes take effect on the next health check interval.
func (c *Client) ModifyApplicationStatusCheck(ctx context.Context, params *ModifyApplicationStatusCheckInput, optFns ...func(*Options)) (*ModifyApplicationStatusCheckOutput, error) {
	if params == nil {
		params = &ModifyApplicationStatusCheckInput{}
	}

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

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

type ModifyApplicationStatusCheckInput struct {

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

	// The aggregation setting for the application status check. When set to included ,
	// the result of this check contributes to the instance-level application status
	// reported by DescribeApplicationStatus . When set to excluded , the check runs
	// independently and does not affect the instance-level status. Valid values:
	// included | excluded .
	Aggregation types.AggregationStatusEnum

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

	// The index of the network device to use for the health check. The value must be
	// greater than or equal to 0.
	DeviceIndex *int32

	// 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 number of consecutive failed health checks before the application status is
	// considered impaired. The value must be greater than 0.
	FailureThreshold *int32

	// The health check paths to use for the application status check.
	HealthCheckPaths []types.HealthCheckPathRequestObject

	// The number of seconds to wait before starting health checks after an instance
	// is launched. Valid values: 1 to 600.
	InitializationGracePeriodSeconds *int32

	// The interval, in seconds, between health checks. Valid value: 60.
	Interval *int32

	// The IP scope to use for the health check. Valid value: private .
	IpScope types.IpScopeEnum

	// The IP version to use for the health check. Valid values: ipv4 and ipv6 .
	IpVersion types.IpVersionEnum

	// The URL path to use for the health check HTTP request (for example, /health or
	// /status ).
	Path *string

	// The port to use for the health check. Valid values: 1 to 65535.
	Port *int32

	// The protocol to use for the health check. Valid values: http | https .
	Protocol types.NetworkProtocolEnum

	// The HTTP status codes that indicate a successful health check response. Specify
	// a comma-separated list of individual status codes or ranges, for example,
	// 200,202,300-399 . For a range, the first value must be less than the second
	// value. Maximum length: 64 characters.
	StatusCodeMatcher *string

	// The number of consecutive successful health checks before the application
	// status is considered healthy. The value must be greater than 0.
	SuccessThreshold *int32

	// The amount of time, in seconds, to wait for a health check response before
	// considering it failed. Valid values: 1 to 30. The value must be less than
	// Interval .
	Timeout *int32

	noSmithyDocumentSerde
}

type ModifyApplicationStatusCheckOutput struct {

	// Information about the modified application status check.
	ApplicationStatusCheck *types.ApplicationStatusCheckResponseObject

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationModifyApplicationStatusCheckMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsEc2query_serializeOpModifyApplicationStatusCheck{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsEc2query_deserializeOpModifyApplicationStatusCheck{}, 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_opModifyApplicationStatusCheckMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpModifyApplicationStatusCheckValidationMiddleware(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_initializeOpModifyApplicationStatusCheck struct {
	tokenProvider IdempotencyTokenProvider
}

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

func (m *idempotencyToken_initializeOpModifyApplicationStatusCheck) 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.(*ModifyApplicationStatusCheckInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *ModifyApplicationStatusCheckInput ")
	}

	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_opModifyApplicationStatusCheckMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpModifyApplicationStatusCheck{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
