// Code generated by sdkgen-v2. DO NOT EDIT.
package iamsdk

import (
	"context"

	iam "github.com/yandex-cloud/go-genproto/yandex/cloud/iam/v1"
	operation "github.com/yandex-cloud/go-genproto/yandex/cloud/operation"
	"github.com/yandex-cloud/go-sdk/v2/pkg/iterator"
	"google.golang.org/grpc"
)

type ApiKeyClientIterator interface {
	Iterator(context.Context, *iam.ListApiKeysRequest, ...grpc.CallOption) *iterator.Iterator[*iam.ListApiKeysRequest, *iam.ApiKey]
	OperationsIterator(context.Context, *iam.ListApiKeyOperationsRequest, ...grpc.CallOption) *iterator.Iterator[*iam.ListApiKeyOperationsRequest, *operation.Operation]
}

type apiKeyServiceListInternal struct {
	*iam.ListApiKeysResponse
}

func (r apiKeyServiceListInternal) Items() []*iam.ApiKey { return r.ListApiKeysResponse.ApiKeys }

func (c apiKeyClient) Iterator(ctx context.Context, req *iam.ListApiKeysRequest, opts ...grpc.CallOption) *iterator.Iterator[*iam.ListApiKeysRequest, *iam.ApiKey] {
	return iterator.NewIterator[*iam.ListApiKeysRequest, *iam.ApiKey](ctx, req,
		func(ctx context.Context, req *iam.ListApiKeysRequest, opts ...grpc.CallOption) (iterator.PageResponse[*iam.ApiKey], error) {
			resp, err := c.List(ctx, req, opts...)
			if err != nil {
				return nil, err
			}
			return apiKeyServiceListInternal{resp}, nil
		})
}

type apiKeyServiceListOperationsInternal struct {
	*iam.ListApiKeyOperationsResponse
}

func (r apiKeyServiceListOperationsInternal) Items() []*operation.Operation {
	return r.ListApiKeyOperationsResponse.Operations
}

func (c apiKeyClient) OperationsIterator(ctx context.Context, req *iam.ListApiKeyOperationsRequest, opts ...grpc.CallOption) *iterator.Iterator[*iam.ListApiKeyOperationsRequest, *operation.Operation] {
	return iterator.NewIterator[*iam.ListApiKeyOperationsRequest, *operation.Operation](ctx, req,
		func(ctx context.Context, req *iam.ListApiKeyOperationsRequest, opts ...grpc.CallOption) (iterator.PageResponse[*operation.Operation], error) {
			resp, err := c.ListOperations(ctx, req, opts...)
			if err != nil {
				return nil, err
			}
			return apiKeyServiceListOperationsInternal{resp}, nil
		})
}
