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

package bedrockagent

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

// Deletes documents from a data source and syncs the changes to the knowledge
// base that is connected to it. For more information, see [Ingest changes directly into a knowledge base]in the Amazon Bedrock
// User Guide.
//
// [Ingest changes directly into a knowledge base]: https://docs.aws.amazon.com/bedrock/latest/userguide/kb-direct-ingestion.html
func (c *Client) DeleteKnowledgeBaseDocuments(ctx context.Context, params *DeleteKnowledgeBaseDocumentsInput, optFns ...func(*Options)) (*DeleteKnowledgeBaseDocumentsOutput, error) {
	if params == nil {
		params = &DeleteKnowledgeBaseDocumentsInput{}
	}

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

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

type DeleteKnowledgeBaseDocumentsInput struct {

	// The unique identifier of the data source that contains the documents.
	//
	// This member is required.
	DataSourceId *string

	// A list of objects, each of which contains information to identify a document to
	// delete.
	//
	// This member is required.
	DocumentIdentifiers []types.DocumentIdentifier

	// The unique identifier of the knowledge base that is connected to the data
	// source.
	//
	// This member is required.
	KnowledgeBaseId *string

	// A unique, case-sensitive identifier to ensure that the API request completes no
	// more than one time. If this token matches a previous request, Amazon Bedrock
	// ignores the request, but does not return an error. For more information, see [Ensuring idempotency].
	//
	// [Ensuring idempotency]: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html
	ClientToken *string

	noSmithyDocumentSerde
}

type DeleteKnowledgeBaseDocumentsOutput struct {

	// A list of objects, each of which contains information about the documents that
	// were deleted.
	DocumentDetails []types.KnowledgeBaseDocumentDetail

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationDeleteKnowledgeBaseDocumentsMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpDeleteKnowledgeBaseDocuments{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpDeleteKnowledgeBaseDocuments{}, 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_opDeleteKnowledgeBaseDocumentsMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpDeleteKnowledgeBaseDocumentsValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "DeleteKnowledgeBaseDocuments"), 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_initializeOpDeleteKnowledgeBaseDocuments struct {
	tokenProvider IdempotencyTokenProvider
}

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

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

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