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

package bedrockagentcorecontrol

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

// Creates a new OAuth2 credential provider.
func (c *Client) CreateOauth2CredentialProvider(ctx context.Context, params *CreateOauth2CredentialProviderInput, optFns ...func(*Options)) (*CreateOauth2CredentialProviderOutput, error) {
	if params == nil {
		params = &CreateOauth2CredentialProviderInput{}
	}

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

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

type CreateOauth2CredentialProviderInput struct {

	// The vendor of the OAuth2 credential provider. This specifies which OAuth2
	// implementation to use.
	//
	// This member is required.
	CredentialProviderVendor types.CredentialProviderVendorType

	// The name of the OAuth2 credential provider. The name must be unique within your
	// account.
	//
	// This member is required.
	Name *string

	// The configuration settings for the OAuth2 provider, including client ID, client
	// secret, and other vendor-specific settings.
	//
	// This member is required.
	Oauth2ProviderConfigInput types.Oauth2ProviderConfigInput

	// A map of tag keys and values to assign to the OAuth2 credential provider. Tags
	// enable you to categorize your resources in different ways, for example, by
	// purpose, owner, or environment.
	Tags map[string]string

	noSmithyDocumentSerde
}

type CreateOauth2CredentialProviderOutput struct {

	// The Amazon Resource Name (ARN) of the client secret in AWS Secrets Manager.
	//
	// This member is required.
	ClientSecretArn *types.Secret

	// The Amazon Resource Name (ARN) of the OAuth2 credential provider.
	//
	// This member is required.
	CredentialProviderArn *string

	// The name of the OAuth2 credential provider.
	//
	// This member is required.
	Name *string

	// Callback URL to register on the OAuth2 credential provider as an allowed
	// callback URL. This URL is where the OAuth2 authorization server redirects users
	// after they complete the authorization flow.
	CallbackUrl *string

	// Contains the output configuration for an OAuth2 provider.
	Oauth2ProviderConfigOutput types.Oauth2ProviderConfigOutput

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateOauth2CredentialProviderMiddlewares(stack *middleware.Stack, options Options) (err error) {
	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
		return err
	}
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateOauth2CredentialProvider{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateOauth2CredentialProvider{}, middleware.After)
	if err != nil {
		return err
	}
	if err := addProtocolFinalizerMiddlewares(stack, options, "CreateOauth2CredentialProvider"); err != nil {
		return fmt.Errorf("add protocol finalizers: %v", err)
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addSetLoggerMiddleware(stack, options); err != nil {
		return err
	}
	if err = addClientRequestID(stack); 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 = addRetry(stack, options); err != nil {
		return err
	}
	if err = addRawResponseToMetadata(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = addSpanRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addClientUserAgent(stack, options); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
		return err
	}
	if err = addTimeOffsetBuild(stack, c); err != nil {
		return err
	}
	if err = addUserAgentRetryMode(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpCreateOauth2CredentialProviderValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateOauth2CredentialProvider(options.Region), middleware.Before); err != nil {
		return err
	}
	if err = addRecursionDetection(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 = addInterceptBeforeRetryLoop(stack, options); err != nil {
		return err
	}
	if err = addInterceptAttempt(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}

func newServiceMetadataMiddleware_opCreateOauth2CredentialProvider(region string) *awsmiddleware.RegisterServiceMetadata {
	return &awsmiddleware.RegisterServiceMetadata{
		Region:        region,
		ServiceID:     ServiceID,
		OperationName: "CreateOauth2CredentialProvider",
	}
}
