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

package bcmdashboards

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

// Triggers an immediate execution of a scheduled report, outside of its regular
// schedule. The scheduled report must be in ENABLED state. Calling this operation
// on a DISABLED scheduled report returns a ValidationException .
//
// If a clientToken is provided, the service uses it for idempotency. Requests
// with the same client token will not trigger a new execution within the same
// minute.
func (c *Client) ExecuteScheduledReport(ctx context.Context, params *ExecuteScheduledReportInput, optFns ...func(*Options)) (*ExecuteScheduledReportOutput, error) {
	if params == nil {
		params = &ExecuteScheduledReportInput{}
	}

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

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

type ExecuteScheduledReportInput struct {

	// The ARN of the scheduled report to execute.
	//
	// This member is required.
	Arn *string

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

	// When set to true , validates the scheduled report configuration without
	// triggering an actual execution.
	DryRun *bool

	noSmithyDocumentSerde
}

type ExecuteScheduledReportOutput struct {

	// Indicates whether the execution was successfully triggered.
	ExecutionTriggered *bool

	// The health status of the scheduled report after the execution request.
	HealthStatus *types.HealthStatus

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationExecuteScheduledReportMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson10_serializeOpExecuteScheduledReport{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpExecuteScheduledReport{}, 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_opExecuteScheduledReportMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpExecuteScheduledReportValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "ExecuteScheduledReport"), 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_initializeOpExecuteScheduledReport struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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