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

package bedrockagentcorecontrol

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

// Retrieves a paginated list of metadata-only policy generation summaries within
// a policy engine without decrypting customer content. This lightweight read
// operation returns resource identifiers, status, timestamps, and findings for
// each policy generation, but does not include status reasons. Because this
// operation does not require access to the customer's KMS key, it is suitable for
// resource discovery, inventory, and integration scenarios where only metadata is
// needed.
func (c *Client) ListPolicyGenerationSummaries(ctx context.Context, params *ListPolicyGenerationSummariesInput, optFns ...func(*Options)) (*ListPolicyGenerationSummariesOutput, error) {
	if params == nil {
		params = &ListPolicyGenerationSummariesInput{}
	}

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

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

type ListPolicyGenerationSummariesInput struct {

	// The identifier of the policy engine whose policy generation summaries to
	// retrieve.
	//
	// This member is required.
	PolicyEngineId *string

	// The maximum number of policy generation summaries to return in a single
	// response.
	MaxResults *int32

	// A pagination token returned from a previous [ListPolicyGenerationSummaries] call. Use this token to retrieve
	// the next page of results when the response is paginated.
	//
	// [ListPolicyGenerationSummaries]: https://docs.aws.amazon.com/bedrock-agentcore-control/latest/APIReference/API_ListPolicyGenerationSummaries.html
	NextToken *string

	noSmithyDocumentSerde
}

type ListPolicyGenerationSummariesOutput struct {

	// An array of policy generation summary objects that match the specified
	// criteria. Each summary contains resource identifiers, status, timestamps, and
	// findings without customer-encrypted content.
	//
	// This member is required.
	PolicyGenerations []types.PolicyGenerationSummary

	// A pagination token that can be used in subsequent [ListPolicyGenerationSummaries] calls to retrieve additional
	// results. This token is only present when there are more results available.
	//
	// [ListPolicyGenerationSummaries]: https://docs.aws.amazon.com/bedrock-agentcore-control/latest/APIReference/API_ListPolicyGenerationSummaries.html
	NextToken *string

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

	noSmithyDocumentSerde
}

func (c *Client) addOperationListPolicyGenerationSummariesMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsRestjson1_serializeOpListPolicyGenerationSummaries{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListPolicyGenerationSummaries{}, 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 = addOpListPolicyGenerationSummariesValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "ListPolicyGenerationSummaries"), 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
}

// ListPolicyGenerationSummariesPaginatorOptions is the paginator options for
// ListPolicyGenerationSummaries
type ListPolicyGenerationSummariesPaginatorOptions struct {
	// The maximum number of policy generation summaries to return in a single
	// response.
	Limit int32

	// Set to true if pagination should stop if the service returns a pagination token
	// that matches the most recent token provided to the service.
	StopOnDuplicateToken bool
}

// ListPolicyGenerationSummariesPaginator is a paginator for
// ListPolicyGenerationSummaries
type ListPolicyGenerationSummariesPaginator struct {
	options   ListPolicyGenerationSummariesPaginatorOptions
	client    ListPolicyGenerationSummariesAPIClient
	params    *ListPolicyGenerationSummariesInput
	nextToken *string
	firstPage bool
}

// NewListPolicyGenerationSummariesPaginator returns a new
// ListPolicyGenerationSummariesPaginator
func NewListPolicyGenerationSummariesPaginator(client ListPolicyGenerationSummariesAPIClient, params *ListPolicyGenerationSummariesInput, optFns ...func(*ListPolicyGenerationSummariesPaginatorOptions)) *ListPolicyGenerationSummariesPaginator {
	if params == nil {
		params = &ListPolicyGenerationSummariesInput{}
	}

	options := ListPolicyGenerationSummariesPaginatorOptions{}
	if params.MaxResults != nil {
		options.Limit = *params.MaxResults
	}

	for _, fn := range optFns {
		fn(&options)
	}

	return &ListPolicyGenerationSummariesPaginator{
		options:   options,
		client:    client,
		params:    params,
		firstPage: true,
		nextToken: params.NextToken,
	}
}

// HasMorePages returns a boolean indicating whether more pages are available
func (p *ListPolicyGenerationSummariesPaginator) HasMorePages() bool {
	return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
}

// NextPage retrieves the next ListPolicyGenerationSummaries page.
func (p *ListPolicyGenerationSummariesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPolicyGenerationSummariesOutput, error) {
	if !p.HasMorePages() {
		return nil, fmt.Errorf("no more pages available")
	}

	params := *p.params
	params.NextToken = p.nextToken

	var limit *int32
	if p.options.Limit > 0 {
		limit = &p.options.Limit
	}
	params.MaxResults = limit

	optFns = append([]func(*Options){
		addIsPaginatorUserAgent,
	}, optFns...)
	result, err := p.client.ListPolicyGenerationSummaries(ctx, &params, optFns...)
	if err != nil {
		return nil, err
	}
	p.firstPage = false

	prevToken := p.nextToken
	p.nextToken = result.NextToken

	if p.options.StopOnDuplicateToken &&
		prevToken != nil &&
		p.nextToken != nil &&
		*prevToken == *p.nextToken {
		p.nextToken = nil
	}

	return result, nil
}

// ListPolicyGenerationSummariesAPIClient is a client that implements the
// ListPolicyGenerationSummaries operation.
type ListPolicyGenerationSummariesAPIClient interface {
	ListPolicyGenerationSummaries(context.Context, *ListPolicyGenerationSummariesInput, ...func(*Options)) (*ListPolicyGenerationSummariesOutput, error)
}

var _ ListPolicyGenerationSummariesAPIClient = (*Client)(nil)
