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

import (
	"context"

	access "github.com/yandex-cloud/go-genproto/yandex/cloud/access"
	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 ServiceAccountClientIterator interface {
	Iterator(context.Context, *iam.ListServiceAccountsRequest, ...grpc.CallOption) *iterator.Iterator[*iam.ListServiceAccountsRequest, *iam.ServiceAccount]
	AccessBindingsIterator(context.Context, *access.ListAccessBindingsRequest, ...grpc.CallOption) *iterator.Iterator[*access.ListAccessBindingsRequest, *access.AccessBinding]
	OperationsIterator(context.Context, *iam.ListServiceAccountOperationsRequest, ...grpc.CallOption) *iterator.Iterator[*iam.ListServiceAccountOperationsRequest, *operation.Operation]
}

type serviceAccountServiceListInternal struct {
	*iam.ListServiceAccountsResponse
}

func (r serviceAccountServiceListInternal) Items() []*iam.ServiceAccount {
	return r.ListServiceAccountsResponse.ServiceAccounts
}

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

type serviceAccountServiceListAccessBindingsInternal struct {
	*access.ListAccessBindingsResponse
}

func (r serviceAccountServiceListAccessBindingsInternal) Items() []*access.AccessBinding {
	return r.ListAccessBindingsResponse.AccessBindings
}

func (c serviceAccountClient) AccessBindingsIterator(ctx context.Context, req *access.ListAccessBindingsRequest, opts ...grpc.CallOption) *iterator.Iterator[*access.ListAccessBindingsRequest, *access.AccessBinding] {
	return iterator.NewIterator[*access.ListAccessBindingsRequest, *access.AccessBinding](ctx, req,
		func(ctx context.Context, req *access.ListAccessBindingsRequest, opts ...grpc.CallOption) (iterator.PageResponse[*access.AccessBinding], error) {
			resp, err := c.ListAccessBindings(ctx, req, opts...)
			if err != nil {
				return nil, err
			}
			return serviceAccountServiceListAccessBindingsInternal{resp}, nil
		})
}

type serviceAccountServiceListOperationsInternal struct {
	*iam.ListServiceAccountOperationsResponse
}

func (r serviceAccountServiceListOperationsInternal) Items() []*operation.Operation {
	return r.ListServiceAccountOperationsResponse.Operations
}

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