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

// Enables Resource Public Key Infrastructure (RPKI) on an existing IPAM internet
// registry association by providing BGP Public Key Infrastructure (BPKI)
// certificate details. After enabling, you can create Route Origin Authorizations
// (ROAs) for prefixes registered with the internet registry.
func (c *Client) EnableIpamInternetRegistryAssociation(ctx context.Context, params *EnableIpamInternetRegistryAssociationInput, optFns ...func(*Options)) (*EnableIpamInternetRegistryAssociationOutput, error) {
	if params == nil {
		params = &EnableIpamInternetRegistryAssociationInput{}
	}

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

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

type EnableIpamInternetRegistryAssociationInput struct {

	// The child handle for the BPKI certificate hierarchy from the Parent Response
	// XML.
	//
	// This member is required.
	ChildHandle *string

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

	// The parent BPKI Trust Anchor certificate in PEM format from the Parent Response
	// XML.
	//
	// This member is required.
	ParentBpkiTa *string

	// The parent handle for the BPKI certificate hierarchy from the Parent Response
	// XML.
	//
	// This member is required.
	ParentHandle *string

	// The RPKI version to use from the Parent Response XML.
	//
	// This member is required.
	RpkiVersion *string

	// The RPKI service URI for the publication point from the Parent Response XML.
	//
	// This member is required.
	ServiceUri *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

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

	noSmithyDocumentSerde
}

type EnableIpamInternetRegistryAssociationOutput struct {

	// Information about the enabled internet registry association.
	IpamInternetRegistryAssociation *types.IpamInternetRegistryAssociation

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationEnableIpamInternetRegistryAssociationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsEc2query_serializeOpEnableIpamInternetRegistryAssociation{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsEc2query_deserializeOpEnableIpamInternetRegistryAssociation{}, 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_opEnableIpamInternetRegistryAssociationMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpEnableIpamInternetRegistryAssociationValidationMiddleware(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_initializeOpEnableIpamInternetRegistryAssociation struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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