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

// Creates a routing policy registration and publishes Route Origin Authorizations
// (ROAs) to the RPKI for the specified CIDR prefix and ASNs.
func (c *Client) CreateIpamRoutingPolicyRegistration(ctx context.Context, params *CreateIpamRoutingPolicyRegistrationInput, optFns ...func(*Options)) (*CreateIpamRoutingPolicyRegistrationOutput, error) {
	if params == nil {
		params = &CreateIpamRoutingPolicyRegistrationInput{}
	}

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

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

type CreateIpamRoutingPolicyRegistrationInput struct {

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

	// The IP address prefix in CIDR notation to authorize in the ROA.
	//
	// 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 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 creation of the routing policy registration even if it conflicts
	// with an announced route. Default: false .
	Force *bool

	// The maximum prefix length that the ASNs are authorized to announce. Must be
	// greater than or equal to the prefix length of the CIDR. If not specified,
	// defaults to the prefix length of the CIDR (exact match only).
	MaxLength *int32

	// Specifies whether to permit more specific route announcements than the CIDR
	// prefix. When enabled, ASNs can announce sub-prefixes of the authorized CIDR up
	// to the specified maximum length. Default: false .
	PermitMoreSpecificAnnouncements *bool

	noSmithyDocumentSerde
}

type CreateIpamRoutingPolicyRegistrationOutput struct {

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

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateIpamRoutingPolicyRegistrationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsEc2query_serializeOpCreateIpamRoutingPolicyRegistration{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateIpamRoutingPolicyRegistration{}, 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_opCreateIpamRoutingPolicyRegistrationMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateIpamRoutingPolicyRegistrationValidationMiddleware(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_initializeOpCreateIpamRoutingPolicyRegistration struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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