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

package cleanrooms

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

// Returns an array that summarizes each privacy budget in a specified
// collaboration. The summary includes the collaboration ARN, creation time,
// creating account, and privacy budget details.
func (c *Client) ListCollaborationPrivacyBudgets(ctx context.Context, params *ListCollaborationPrivacyBudgetsInput, optFns ...func(*Options)) (*ListCollaborationPrivacyBudgetsOutput, error) {
	if params == nil {
		params = &ListCollaborationPrivacyBudgetsInput{}
	}

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

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

type ListCollaborationPrivacyBudgetsInput struct {

	// A unique identifier for one of your collaborations.
	//
	// This member is required.
	CollaborationIdentifier *string

	// Specifies the type of the privacy budget.
	//
	// This member is required.
	PrivacyBudgetType types.PrivacyBudgetType

	// The Amazon Resource Name (ARN) of the Configured Table Association
	// (ConfiguredTableAssociation) used to filter privacy budgets.
	AccessBudgetResourceArn *string

	// The maximum number of results that are returned for an API request call. The
	// service chooses a default number if you don't set one. The service might return
	// a `nextToken` even if the `maxResults` value has not been met.
	MaxResults *int32

	// The pagination token that's used to fetch the next set of results.
	NextToken *string

	noSmithyDocumentSerde
}

type ListCollaborationPrivacyBudgetsOutput struct {

	// Summaries of the collaboration privacy budgets.
	//
	// This member is required.
	CollaborationPrivacyBudgetSummaries []types.CollaborationPrivacyBudgetSummary

	// The pagination token that's used to fetch the next set of results.
	NextToken *string

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

	noSmithyDocumentSerde
}

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

// ListCollaborationPrivacyBudgetsPaginatorOptions is the paginator options for
// ListCollaborationPrivacyBudgets
type ListCollaborationPrivacyBudgetsPaginatorOptions struct {
	// The maximum number of results that are returned for an API request call. The
	// service chooses a default number if you don't set one. The service might return
	// a `nextToken` even if the `maxResults` value has not been met.
	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
}

// ListCollaborationPrivacyBudgetsPaginator is a paginator for
// ListCollaborationPrivacyBudgets
type ListCollaborationPrivacyBudgetsPaginator struct {
	options   ListCollaborationPrivacyBudgetsPaginatorOptions
	client    ListCollaborationPrivacyBudgetsAPIClient
	params    *ListCollaborationPrivacyBudgetsInput
	nextToken *string
	firstPage bool
}

// NewListCollaborationPrivacyBudgetsPaginator returns a new
// ListCollaborationPrivacyBudgetsPaginator
func NewListCollaborationPrivacyBudgetsPaginator(client ListCollaborationPrivacyBudgetsAPIClient, params *ListCollaborationPrivacyBudgetsInput, optFns ...func(*ListCollaborationPrivacyBudgetsPaginatorOptions)) *ListCollaborationPrivacyBudgetsPaginator {
	if params == nil {
		params = &ListCollaborationPrivacyBudgetsInput{}
	}

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

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

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

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

// NextPage retrieves the next ListCollaborationPrivacyBudgets page.
func (p *ListCollaborationPrivacyBudgetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListCollaborationPrivacyBudgetsOutput, 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.ListCollaborationPrivacyBudgets(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
}

// ListCollaborationPrivacyBudgetsAPIClient is a client that implements the
// ListCollaborationPrivacyBudgets operation.
type ListCollaborationPrivacyBudgetsAPIClient interface {
	ListCollaborationPrivacyBudgets(context.Context, *ListCollaborationPrivacyBudgetsInput, ...func(*Options)) (*ListCollaborationPrivacyBudgetsOutput, error)
}

var _ ListCollaborationPrivacyBudgetsAPIClient = (*Client)(nil)
