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

package sts

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

// Exchanges a trade-in token for temporary Amazon Web Services credentials with
// the permissions associated with the assumed principal. This operation allows you
// to obtain credentials for a specific principal based on a trade-in token,
// enabling delegation of access to Amazon Web Services resources.
func (c *Client) GetDelegatedAccessToken(ctx context.Context, params *GetDelegatedAccessTokenInput, optFns ...func(*Options)) (*GetDelegatedAccessTokenOutput, error) {
	if params == nil {
		params = &GetDelegatedAccessTokenInput{}
	}

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

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

type GetDelegatedAccessTokenInput struct {

	// The token to exchange for temporary Amazon Web Services credentials. This token
	// must be valid and unexpired at the time of the request.
	//
	// This member is required.
	TradeInToken *string

	noSmithyDocumentSerde
}

type GetDelegatedAccessTokenOutput struct {

	// The Amazon Resource Name (ARN) of the principal that was assumed when obtaining
	// the delegated access token. This ARN identifies the IAM entity whose permissions
	// are granted by the temporary credentials.
	AssumedPrincipal *string

	// Amazon Web Services credentials for API authentication.
	Credentials *types.Credentials

	// The percentage of the maximum policy size that is used by the session policy.
	// The policy size is calculated as the sum of all the session policies and
	// permission boundaries attached to the session. If the packed size exceeds 100%,
	// the request fails.
	PackedPolicySize *int32

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

	noSmithyDocumentSerde
}

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