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

package appconfig

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

// Stops a running experiment. Stopping an experiment run ends audience exposure
// and returns users to the currently deployed feature flag configuration.
func (c *Client) StopExperimentRun(ctx context.Context, params *StopExperimentRunInput, optFns ...func(*Options)) (*StopExperimentRunOutput, error) {
	if params == nil {
		params = &StopExperimentRunInput{}
	}

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

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

type StopExperimentRunInput struct {

	// The application ID or name.
	//
	// This member is required.
	ApplicationIdentifier *string

	// The experiment definition ID or name.
	//
	// This member is required.
	ExperimentDefinitionIdentifier *string

	// The run number to stop.
	//
	// This member is required.
	Run *int32

	// The deployment parameters for the stop operation.
	DeploymentParameters *types.DeploymentParameters

	// The result of the experiment run, including an executive summary and reasons
	// for or against launching.
	Result *types.ExperimentRunResult

	noSmithyDocumentSerde
}

// Describes an experiment run, including its status, exposure settings, and
// treatment overrides.
type StopExperimentRunOutput struct {

	// The application ID.
	ApplicationId *string

	// A description of the experiment run.
	Description *string

	// The date and time the experiment run ended, in ISO 8601 format.
	EndedAt *time.Time

	// The experiment definition ID.
	ExperimentDefinitionId *string

	// A snapshot of the experiment definition at the time the run was started.
	ExperimentDefinitionSnapshot *types.ExperimentDefinitionSnapshot

	// The percentage of the target audience exposed to treatments.
	ExposurePercentage *float32

	// The result of the experiment run, including the executive summary and launch
	// decision rationale.
	Result *types.ExperimentRunResult

	// The experiment run number.
	Run int32

	// The date and time the experiment run started, in ISO 8601 format.
	StartedAt *time.Time

	// The current status of the experiment run. Valid values: RUNNING , DONE .
	Status types.ExperimentRunStatus

	// Treatment assignment overrides that assign specific entity IDs to treatments.
	TreatmentOverrides types.TreatmentOverrides

	// The date and time the experiment run was last updated, in ISO 8601 format.
	UpdatedAt *time.Time

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

	noSmithyDocumentSerde
}

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