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

package deadline

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

// Gets a session action for the job.
func (c *Client) GetSessionAction(ctx context.Context, params *GetSessionActionInput, optFns ...func(*Options)) (*GetSessionActionOutput, error) {
	if params == nil {
		params = &GetSessionActionInput{}
	}

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

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

type GetSessionActionInput struct {

	// The farm ID for the session action.
	//
	// This member is required.
	FarmId *string

	// The job ID for the session.
	//
	// This member is required.
	JobId *string

	// The queue ID for the session action.
	//
	// This member is required.
	QueueId *string

	// The session action ID for the session.
	//
	// This member is required.
	SessionActionId *string

	noSmithyDocumentSerde
}

type GetSessionActionOutput struct {

	// The session action definition.
	//
	// This member is required.
	Definition types.SessionActionDefinition

	// The session action ID.
	//
	// This member is required.
	SessionActionId *string

	// The session ID for the session action.
	//
	// This member is required.
	SessionId *string

	// The status of the session action.
	//
	// This member is required.
	Status types.SessionActionStatus

	// The limits and their amounts acquired during a session action. If no limits
	// were acquired during the session, this field isn't returned.
	AcquiredLimits []types.AcquiredLimit

	// The date and time the resource ended running.
	EndedAt *time.Time

	// The list of manifest properties that describe file attachments for the task run.
	Manifests []types.TaskRunManifestPropertiesResponse

	// The process exit code. The default Deadline Cloud worker agent converts
	// unsigned 32-bit exit codes to signed 32-bit exit codes.
	ProcessExitCode *int32

	// The message that communicates the progress of the session action.
	ProgressMessage *string

	// The percentage completed for a session action.
	ProgressPercent *float32

	// The date and time the resource started running.
	StartedAt *time.Time

	// The Linux timestamp of the date and time the session action was last updated.
	WorkerUpdatedAt *time.Time

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationGetSessionActionMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpGetSessionAction{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpGetSessionAction{}, 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 = addEndpointPrefix_opGetSessionActionMiddleware(stack); err != nil {
		return err
	}
	if err = addOpGetSessionActionValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "GetSessionAction"), 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 endpointPrefix_opGetSessionActionMiddleware struct {
}

func (*endpointPrefix_opGetSessionActionMiddleware) ID() string {
	return "EndpointHostPrefix"
}

func (m *endpointPrefix_opGetSessionActionMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
	out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
	if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) {
		return next.HandleFinalize(ctx, in)
	}

	req, ok := in.Request.(*smithyhttp.Request)
	if !ok {
		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
	}

	req.URL.Host = "management." + req.URL.Host

	return next.HandleFinalize(ctx, in)
}
func addEndpointPrefix_opGetSessionActionMiddleware(stack *middleware.Stack) error {
	return stack.Finalize.Insert(&endpointPrefix_opGetSessionActionMiddleware{}, "ResolveEndpointV2", middleware.After)
}
