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

package cognitoidentityprovider

import (
	"context"
	"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

// A user pool domain hosts managed login, an authorization server and web server
// for authentication in your application. This operation creates a new user pool
// prefix domain or custom domain and sets the managed login branding version. Set
// the branding version to 1 for hosted UI (classic) or 2 for managed login. When
// you choose a custom domain, you must provide an SSL certificate in the US East
// (N. Virginia) Amazon Web Services Region in your request.
//
// Your prefix domain might take up to one minute to take effect. Your custom
// domain is online within five minutes, but it can take up to one hour to
// distribute your SSL certificate.
//
// For more information about adding a custom domain to your user pool, see [Configuring a user pool domain].
//
// Amazon Cognito evaluates Identity and Access Management (IAM) policies in
// requests for this API operation. For this operation, you must use IAM
// credentials to authorize requests, and you must grant yourself the corresponding
// IAM permission in a policy.
//
// # Learn more
//
// [Signing Amazon Web Services API Requests]
//
// [Using the Amazon Cognito user pools API and user pool endpoints]
//
// [Using the Amazon Cognito user pools API and user pool endpoints]: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pools-API-operations.html
// [Configuring a user pool domain]: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-add-custom-domain.html
// [Signing Amazon Web Services API Requests]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html
func (c *Client) CreateUserPoolDomain(ctx context.Context, params *CreateUserPoolDomainInput, optFns ...func(*Options)) (*CreateUserPoolDomainOutput, error) {
	if params == nil {
		params = &CreateUserPoolDomainInput{}
	}

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

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

type CreateUserPoolDomainInput struct {

	// The domain string. For custom domains, this is the fully-qualified domain name,
	// such as auth.example.com . For prefix domains, this is the prefix alone, such as
	// myprefix . A prefix value of myprefix for a user pool in the us-east-1 Region
	// results in a domain of myprefix.auth.us-east-1.amazoncognito.com .
	//
	// This member is required.
	Domain *string

	// The ID of the user pool where you want to add a domain.
	//
	// This member is required.
	UserPoolId *string

	// The configuration for a custom domain. Configures your domain with an
	// Certificate Manager certificate in the us-east-1 Region.
	//
	// Provide this parameter only if you want to use a [custom domain] for your user pool.
	// Otherwise, you can omit this parameter and use a [prefix domain]instead.
	//
	// When you create a custom domain, the passkey RP ID defaults to the custom
	// domain. If you had a prefix domain active, this will cause passkey integration
	// for your prefix domain to stop working due to a mismatch in RP ID. To keep the
	// prefix domain passkey integration working, you can explicitly set RP ID to the
	// prefix domain.
	//
	// [custom domain]: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-add-custom-domain.html
	// [prefix domain]: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-assign-domain-prefix.html
	CustomDomainConfig *types.CustomDomainConfigType

	// The version of managed login branding that you want to apply to your domain. A
	// value of 1 indicates hosted UI (classic) and a version of 2 indicates managed
	// login.
	//
	// Managed login requires that your user pool be configured for any [feature plan] other than
	// Lite .
	//
	// [feature plan]: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-sign-in-feature-plans.html
	ManagedLoginVersion *int32

	// The configuration of routing for requests to the domain for replicas of a
	// replicated user pool. The routing configuration is currently only supported for
	// custom domains.
	Routing *types.RoutingType

	noSmithyDocumentSerde
}

type CreateUserPoolDomainOutput struct {

	// The fully-qualified domain name (FQDN) of the Amazon CloudFront distribution
	// that hosts your managed login or classic hosted UI pages. Your domain-name
	// authority must have an alias record that points requests for your custom domain
	// to this FQDN. Amazon Cognito returns this value if you set a custom domain with
	// CustomDomainConfig . If you set an Amazon Cognito prefix domain, this parameter
	// returns null.
	CloudFrontDomain *string

	// The version of managed login branding applied your domain. A value of 1
	// indicates hosted UI (classic) and a version of 2 indicates managed login.
	ManagedLoginVersion *int32

	// The routing configuration that was applied to the user pool domain.
	Routing *types.RoutingType

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateUserPoolDomainMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateUserPoolDomain{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateUserPoolDomain{}, 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); 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 = addOpCreateUserPoolDomainValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateUserPoolDomain"), 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
}
