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

package bedrockagentcore

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

// Processes a payment using a payment instrument within a payment session.
func (c *Client) ProcessPayment(ctx context.Context, params *ProcessPaymentInput, optFns ...func(*Options)) (*ProcessPaymentOutput, error) {
	if params == nil {
		params = &ProcessPaymentInput{}
	}

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

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

// Request structure for processing a payment.
type ProcessPaymentInput struct {

	// The payment input details specific to the payment type.
	//
	// This member is required.
	PaymentInput types.PaymentInput

	// The ID of the payment instrument to use.
	//
	// This member is required.
	PaymentInstrumentId *string

	// The ARN of the payment manager.
	//
	// This member is required.
	PaymentManagerArn *string

	// The ID of the payment session.
	//
	// This member is required.
	PaymentSessionId *string

	// The type of payment to process.
	//
	// This member is required.
	PaymentType types.PaymentType

	// The agent name associated with this request, used for observability.
	AgentName *string

	// A unique, case-sensitive identifier that you provide to ensure the idempotency
	// of the request.
	ClientToken *string

	// The user ID associated with this payment.
	UserId *string

	noSmithyDocumentSerde
}

// Response structure for processing a payment.
type ProcessPaymentOutput struct {

	// The timestamp when the payment was created.
	//
	// This member is required.
	CreatedAt *time.Time

	// The ID of the payment instrument used.
	//
	// This member is required.
	PaymentInstrumentId *string

	// The ARN of the payment manager.
	//
	// This member is required.
	PaymentManagerArn *string

	// The payment output details specific to the payment type.
	//
	// This member is required.
	PaymentOutput types.PaymentOutput

	// The ID of the payment session used.
	//
	// This member is required.
	PaymentSessionId *string

	// The type of payment processed.
	//
	// This member is required.
	PaymentType types.PaymentType

	// The unique identifier of the processed payment.
	//
	// This member is required.
	ProcessPaymentId *string

	// The status of the payment.
	//
	// This member is required.
	Status types.PaymentStatus

	// The timestamp when the payment was last updated.
	//
	// This member is required.
	UpdatedAt *time.Time

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationProcessPaymentMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpProcessPayment{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpProcessPayment{}, 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 = addIdempotencyToken_opProcessPaymentMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpProcessPaymentValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "ProcessPayment"), 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
}

type idempotencyToken_initializeOpProcessPayment struct {
	tokenProvider IdempotencyTokenProvider
}

func (*idempotencyToken_initializeOpProcessPayment) ID() string {
	return "OperationIdempotencyTokenAutoFill"
}

func (m *idempotencyToken_initializeOpProcessPayment) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
	if m.tokenProvider == nil {
		return next.HandleInitialize(ctx, in)
	}

	input, ok := in.Parameters.(*ProcessPaymentInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *ProcessPaymentInput ")
	}

	if input.ClientToken == nil {
		t, err := m.tokenProvider.GetIdempotencyToken()
		if err != nil {
			return out, metadata, err
		}
		input.ClientToken = &t
	}
	return next.HandleInitialize(ctx, in)
}
func addIdempotencyToken_opProcessPaymentMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpProcessPayment{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
