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

// Modifies an existing routing policy registration. You can update the authorized
// ASNs, maximum prefix length, and other properties of a Route Origin
// Authorization (ROA).
func (c *Client) ModifyIpamRoutingPolicyRegistration(ctx context.Context, params *ModifyIpamRoutingPolicyRegistrationInput, optFns ...func(*Options)) (*ModifyIpamRoutingPolicyRegistrationOutput, error) {
	if params == nil {
		params = &ModifyIpamRoutingPolicyRegistrationInput{}
	}

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

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

type ModifyIpamRoutingPolicyRegistrationInput struct {

	// The updated list of Autonomous System Numbers (ASNs) authorized to originate
	// the prefix.
	//
	// This member is required.
	Asns []string

	// The IP address prefix in CIDR notation identifying the routing policy
	// registration to modify.
	//
	// This member is required.
	Cidr *string

	// The ID of the IPAM internet registry association.
	//
	// This member is required.
	IpamInternetRegistryAssociationId *string

	// A unique, case-sensitive identifier to ensure that the operation completes no
	// more than one time. If this token matches a previous request, the operation
	// ignores the request, but does not return an error.
	ClientToken *string

	// A new description for the routing policy registration.
	Description *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

	// Forces the modification even if it conflicts with an announced route. Default:
	// false .
	Force *bool

	// The new maximum prefix length that the ASNs are authorized to announce. Must be
	// greater than or equal to the prefix length of the CIDR.
	MaxLength *int32

	// Specifies whether to permit more specific route announcements than the CIDR
	// prefix. Default: false .
	PermitMoreSpecificAnnouncements *bool

	noSmithyDocumentSerde
}

type ModifyIpamRoutingPolicyRegistrationOutput struct {

	// Information about the routing policy registration delta created by this
	// modification.
	IpamRoutingPolicyRegistrationDelta *types.IpamRoutingPolicyRegistrationDelta

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationModifyIpamRoutingPolicyRegistrationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsEc2query_serializeOpModifyIpamRoutingPolicyRegistration{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsEc2query_deserializeOpModifyIpamRoutingPolicyRegistration{}, 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, options); 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 = addIdempotencyToken_opModifyIpamRoutingPolicyRegistrationMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpModifyIpamRoutingPolicyRegistrationValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "ModifyIpamRoutingPolicyRegistration"), 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
}

type idempotencyToken_initializeOpModifyIpamRoutingPolicyRegistration struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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