// 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 KeyClientIterator interface {
	Iterator(context.Context, *iam.ListKeysRequest, ...grpc.CallOption) *iterator.Iterator[*iam.ListKeysRequest, *iam.Key]
	OperationsIterator(context.Context, *iam.ListKeyOperationsRequest, ...grpc.CallOption) *iterator.Iterator[*iam.ListKeyOperationsRequest, *operation.Operation]
}

type keyServiceListInternal struct {
	*iam.ListKeysResponse
}

func (r keyServiceListInternal) Items() []*iam.Key { return r.ListKeysResponse.Keys }

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

type keyServiceListOperationsInternal struct {
	*iam.ListKeyOperationsResponse
}

func (r keyServiceListOperationsInternal) Items() []*operation.Operation {
	return r.ListKeyOperationsResponse.Operations
}

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