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

package cognitoidentityprovider

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

// Creates an IdP for a user pool.
func (c *Client) CreateIdentityProvider(ctx context.Context, params *CreateIdentityProviderInput, optFns ...func(*Options)) (*CreateIdentityProviderOutput, error) {
	if params == nil {
		params = &CreateIdentityProviderInput{}
	}

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

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

type CreateIdentityProviderInput struct {

	// The IdP details. The following list describes the provider detail keys for each
	// IdP type.
	//
	// * For Google and Login with Amazon:
	//
	// * client_id
	//
	// * client_secret
	//
	// *
	// authorize_scopes
	//
	// * For Facebook:
	//
	// * client_id
	//
	// * client_secret
	//
	// *
	// authorize_scopes
	//
	// * api_version
	//
	// * For Sign in with Apple:
	//
	// * client_id
	//
	// *
	// team_id
	//
	// * key_id
	//
	// * private_key
	//
	// * authorize_scopes
	//
	// * For OpenID Connect
	// (OIDC) providers:
	//
	// * client_id
	//
	// * client_secret
	//
	// * attributes_request_method
	//
	// *
	// oidc_issuer
	//
	// * authorize_scopes
	//
	// * The following keys are only present if Amazon
	// Cognito didn't discover them at the oidc_issuer URL.
	//
	// * authorize_url
	//
	// *
	// token_url
	//
	// * attributes_url
	//
	// * jwks_uri
	//
	// * Amazon Cognito sets the value of the
	// following keys automatically. They are read-only.
	//
	// *
	// attributes_url_add_attributes
	//
	// * For SAML providers:
	//
	// * MetadataFile or
	// MetadataURL
	//
	// * IDPSignout optional
	//
	// This member is required.
	ProviderDetails map[string]string

	// The IdP name.
	//
	// This member is required.
	ProviderName *string

	// The IdP type.
	//
	// This member is required.
	ProviderType types.IdentityProviderTypeType

	// The user pool ID.
	//
	// This member is required.
	UserPoolId *string

	// A mapping of IdP attributes to standard and custom user pool attributes.
	AttributeMapping map[string]string

	// A list of IdP identifiers.
	IdpIdentifiers []string

	noSmithyDocumentSerde
}

type CreateIdentityProviderOutput struct {

	// The newly created IdP object.
	//
	// This member is required.
	IdentityProvider *types.IdentityProviderType

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateIdentityProviderMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateIdentityProvider{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateIdentityProvider{}, middleware.After)
	if err != nil {
		return err
	}
	if err = addSetLoggerMiddleware(stack, options); err != nil {
		return err
	}
	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
		return err
	}
	if err = addRetryMiddlewares(stack, options); err != nil {
		return err
	}
	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
		return err
	}
	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
		return err
	}
	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = addClientUserAgent(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 = addOpCreateIdentityProviderValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateIdentityProvider(options.Region), 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
	}
	return nil
}

func newServiceMetadataMiddleware_opCreateIdentityProvider(region string) *awsmiddleware.RegisterServiceMetadata {
	return &awsmiddleware.RegisterServiceMetadata{
		Region:        region,
		ServiceID:     ServiceID,
		SigningName:   "cognito-idp",
		OperationName: "CreateIdentityProvider",
	}
}
