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

package acm

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

// Creates a domain validation for an ACME endpoint. Domain validations authorize
// the endpoint to issue certificates for specified domain names. You configure
// prevalidation to prove domain ownership.
func (c *Client) CreateAcmeDomainValidation(ctx context.Context, params *CreateAcmeDomainValidationInput, optFns ...func(*Options)) (*CreateAcmeDomainValidationOutput, error) {
	if params == nil {
		params = &CreateAcmeDomainValidationInput{}
	}

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

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

type CreateAcmeDomainValidationInput struct {

	// The Amazon Resource Name (ARN) of the ACME endpoint.
	//
	// This member is required.
	AcmeEndpointArn *string

	// The domain name to validate.
	//
	// This member is required.
	DomainName *string

	// The prevalidation options for the domain.
	//
	// This member is required.
	PrevalidationOptions types.PrevalidationOptions

	// A unique, case-sensitive identifier to ensure idempotency of the request.
	IdempotencyToken *string

	// One or more tags to associate with the domain validation.
	Tags []types.Tag

	noSmithyDocumentSerde
}

func (in *CreateAcmeDomainValidationInput) bindEndpointParams(p *EndpointParameters) {

	p.ServiceType = ptr.String("ACM-ACME")
}

type CreateAcmeDomainValidationOutput struct {

	// The Amazon Resource Name (ARN) of the created domain validation.
	//
	// This member is required.
	AcmeDomainValidationArn *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateAcmeDomainValidationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateAcmeDomainValidation{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateAcmeDomainValidation{}, middleware.After)
	if 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 = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addIdempotencyToken_opCreateAcmeDomainValidationMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateAcmeDomainValidationValidationMiddleware(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_initializeOpCreateAcmeDomainValidation struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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