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

// Updates an existing scraper.
//
// You can't use this function to update the source from which the scraper is
// collecting metrics. To change the source, delete the scraper and create a new
// one.
func (c *Client) UpdateScraper(ctx context.Context, params *UpdateScraperInput, optFns ...func(*Options)) (*UpdateScraperOutput, error) {
	if params == nil {
		params = &UpdateScraperInput{}
	}

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

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

type UpdateScraperInput struct {

	// The ID of the scraper to update.
	//
	// This member is required.
	ScraperId *string

	// The new alias of the scraper.
	Alias *string

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

	// The new Amazon Managed Service for Prometheus workspace to send metrics to.
	Destination types.Destination

	// Use this structure to enable cross-account access, so that you can use a target
	// account to access Prometheus metrics from source accounts.
	RoleConfiguration *types.RoleConfiguration

	// Contains the base-64 encoded YAML configuration for the scraper.
	//
	// For more information about configuring a scraper, see [Using an Amazon Web Services managed collector] in the Amazon Managed
	// Service for Prometheus User Guide.
	//
	// [Using an Amazon Web Services managed collector]: https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-collector-how-to.html
	ScrapeConfiguration types.ScrapeConfiguration

	noSmithyDocumentSerde
}

type UpdateScraperOutput struct {

	// The Amazon Resource Name (ARN) of the updated scraper.
	//
	// This member is required.
	Arn *string

	// The ID of the updated scraper.
	//
	// This member is required.
	ScraperId *string

	// A structure that displays the current status of the scraper.
	//
	// This member is required.
	Status *types.ScraperStatus

	// The list of tag keys and values that are associated with the scraper.
	Tags map[string]string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationUpdateScraperMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpUpdateScraper{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpUpdateScraper{}, 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_opUpdateScraperMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpUpdateScraperValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "UpdateScraper"), 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_initializeOpUpdateScraper struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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