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

package amp

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

// Use this operation to create or update the label sets, label set limits, and
// retention period of a workspace.
//
// You must specify at least one of limitsPerLabelSet or retentionPeriodInDays for
// the request to be valid.
func (c *Client) UpdateWorkspaceConfiguration(ctx context.Context, params *UpdateWorkspaceConfigurationInput, optFns ...func(*Options)) (*UpdateWorkspaceConfigurationOutput, error) {
	if params == nil {
		params = &UpdateWorkspaceConfigurationInput{}
	}

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

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

type UpdateWorkspaceConfigurationInput struct {

	// The ID of the workspace that you want to update. To find the IDs of your
	// workspaces, use the [ListWorkspaces]operation.
	//
	// [ListWorkspaces]: https://docs.aws.amazon.com/prometheus/latest/APIReference/API_ListWorkspaces.htm
	//
	// This member is required.
	WorkspaceId *string

	// You can include a token in your operation to make it an idempotent opeartion.
	ClientToken *string

	// This is an array of structures, where each structure defines a label set for
	// the workspace, and defines the active time series limit for each of those label
	// sets. Each label name in a label set must be unique.
	LimitsPerLabelSet []types.LimitsPerLabelSet

	// Specifies the time window in seconds for accepting out of order samples. Out of
	// order samples older than this window are rejected.
	OutOfOrderTimeWindowInSeconds *int32

	// Specifies how many days that metrics will be retained in the workspace.
	RetentionPeriodInDays *int32

	// Specifies the duration in seconds to offset rule evaluation queries into the
	// past. This allows ingested samples to be available before rule evaluation.
	RuleQueryOffsetInSeconds *int32

	noSmithyDocumentSerde
}

type UpdateWorkspaceConfigurationOutput struct {

	// The status of the workspace configuration.
	//
	// This member is required.
	Status *types.WorkspaceConfigurationStatus

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationUpdateWorkspaceConfigurationMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpUpdateWorkspaceConfiguration{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpUpdateWorkspaceConfiguration{}, 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_opUpdateWorkspaceConfigurationMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpUpdateWorkspaceConfigurationValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "UpdateWorkspaceConfiguration"), 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_initializeOpUpdateWorkspaceConfiguration struct {
	tokenProvider IdempotencyTokenProvider
}

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

func (m *idempotencyToken_initializeOpUpdateWorkspaceConfiguration) 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.(*UpdateWorkspaceConfigurationInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *UpdateWorkspaceConfigurationInput ")
	}

	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_opUpdateWorkspaceConfigurationMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpUpdateWorkspaceConfiguration{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
