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

package signin

import (
	"context"
	"github.com/aws/smithy-go/middleware"
	"github.com/aws/smithy-go/ptr"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

// Grants permission to exchange client credentials for an OAuth 2.0 access token
// scoped to a resource that can be used to access AWS services from applications
func (c *Client) CreateOAuth2TokenWithIAM(ctx context.Context, params *CreateOAuth2TokenWithIAMInput, optFns ...func(*Options)) (*CreateOAuth2TokenWithIAMOutput, error) {
	if params == nil {
		params = &CreateOAuth2TokenWithIAMInput{}
	}

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

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

// Input structure for CreateOAuth2TokenWithIAM operation
type CreateOAuth2TokenWithIAMInput struct {

	// OAuth 2.0 grant type. Must be "client_credentials".
	//
	// This member is required.
	GrantType *string

	// The OAuth resource for which the access token is requested. Example:
	// "aws-mcp.amazonaws.com".
	//
	// This member is required.
	Resource *string

	noSmithyDocumentSerde
}

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

	p.IsOAuthEndpoint = ptr.Bool(true)
}

// Output structure for CreateOAuth2TokenWithIAM operation
//
// Contains the JWT access token, token type, and expiration per RFC 6749 §5.1.
type CreateOAuth2TokenWithIAMOutput struct {

	// JWT access token containing principal identity, resource scope, and session
	// metadata
	//
	// This member is required.
	AccessToken *string

	// Token lifetime in seconds. Value is the minimum of session validity and 1 hour.
	//
	// This member is required.
	ExpiresIn *int32

	// Always "Bearer" per OAuth 2.1 specification
	//
	// This member is required.
	TokenType *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateOAuth2TokenWithIAMMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateOAuth2TokenWithIAM{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateOAuth2TokenWithIAM{}, 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, 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 = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpCreateOAuth2TokenWithIAMValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateOAuth2TokenWithIAM"), 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
}
