// 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"
)

// Creates a new scheduled report for a dashboard. A scheduled report
// automatically generates and delivers dashboard snapshots on a recurring
// schedule. Reports are delivered within 15 minutes of the scheduled delivery
// time.
func (c *Client) CreateScheduledReport(ctx context.Context, params *CreateScheduledReportInput, optFns ...func(*Options)) (*CreateScheduledReportOutput, error) {
	if params == nil {
		params = &CreateScheduledReportInput{}
	}

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

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

type CreateScheduledReportInput struct {

	// The configuration for the scheduled report, including the dashboard to report
	// on, the schedule, and the execution role that the service will use to generate
	// the dashboard snapshot.
	//
	// This member is required.
	ScheduledReport *types.ScheduledReportInput

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

	// The tags to apply to the scheduled report resource for organization and
	// management.
	ResourceTags []types.ResourceTag

	noSmithyDocumentSerde
}

type CreateScheduledReportOutput struct {

	// The ARN of the newly created scheduled report.
	//
	// This member is required.
	Arn *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationCreateScheduledReportMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson10_serializeOpCreateScheduledReport{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpCreateScheduledReport{}, 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 = addIdempotencyToken_opCreateScheduledReportMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateScheduledReportValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "CreateScheduledReport"), 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_initializeOpCreateScheduledReport struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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