/*
Copyright The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Code generated by informer-gen. DO NOT EDIT.

package v1

import (
	context "context"
	time "time"

	apirbacv1 "k8s.io/api/rbac/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	runtime "k8s.io/apimachinery/pkg/runtime"
	schema "k8s.io/apimachinery/pkg/runtime/schema"
	watch "k8s.io/apimachinery/pkg/watch"
	internalinterfaces "k8s.io/client-go/informers/internalinterfaces"
	kubernetes "k8s.io/client-go/kubernetes"
	rbacv1 "k8s.io/client-go/listers/rbac/v1"
	cache "k8s.io/client-go/tools/cache"
)

// RoleInformer provides access to a shared informer and lister for
// Roles. Prefer using the type-safe variant (see [TypedRoleInformer]).
type RoleInformer interface {
	Informer() cache.SharedIndexInformer
	Lister() rbacv1.RoleLister
}

// TypedRoleInformer provides access to a shared informer and lister for
// Roles, including the type-safe TypedInformer variant.
// It is a superset of RoleInformer.
type TypedRoleInformer interface {
	Informer() cache.SharedIndexInformer
	TypedInformer() RoleIndexInformer
	Lister() rbacv1.RoleLister
}

// RoleIndexInformer is a wrapper around the underlying [cache.SharedIndexInformer]
// with type-safe variants of several methods.
type RoleIndexInformer cache.TypedSharedIndexInformer[*apirbacv1.Role]

// RoleHandlerFuncs is a specialization of [cache.TypedResourceEventHandlerFuncs] for Role.
type RoleHandlerFuncs = cache.TypedResourceEventHandlerFuncs[*apirbacv1.Role]

// RoleDetailedHandlerFuncs is a specialization of [cache.TypedResourceEventHandlerDetailedFuncs] for Role.
type RoleDetailedHandlerFuncs = cache.TypedResourceEventHandlerDetailedFuncs[*apirbacv1.Role]

// RoleFilteringHandler is a specialization of [cache.TypedFilteringResourceEventHandler] for Role.
type RoleFilteringHandler = cache.TypedFilteringResourceEventHandler[*apirbacv1.Role]

// RoleIndexers is a specialization of [cache.TypedIndexers] for Role.
type RoleIndexers = cache.TypedIndexers[*apirbacv1.Role]

// DeletedRole is a specialization of [cache.DeletedObject] for Role.
type DeletedRole = cache.DeletedObject[*apirbacv1.Role]

type roleInformer struct {
	factory          internalinterfaces.SharedInformerFactory
	tweakListOptions internalinterfaces.TweakListOptionsFunc
	namespace        string
}

// NewRoleInformer constructs a new informer for Role type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
// If you really need an independent one, prefer using the type-safe variant (see [NewTypedRoleInformer]).
func NewRoleInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
	return NewRoleInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: indexers})
}

// NewTypedRoleInformer constructs a new informer for Role type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewTypedRoleInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers RoleIndexers) RoleIndexInformer {
	return NewTypedRoleInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: cache.TypedIndexersToIndexers(indexers)})
}

// NewFilteredRoleInformer constructs a new informer for Role type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
// If you really need an independent one, prefer using the type-safe variant (see [NewTypedFilteredRoleInformer]).
func NewFilteredRoleInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
	return NewTypedRoleInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: indexers, TweakListOptions: tweakListOptions})
}

// NewTypedFilteredRoleInformer constructs a new informer for Role type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewTypedFilteredRoleInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers RoleIndexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) RoleIndexInformer {
	return NewTypedRoleInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: cache.TypedIndexersToIndexers(indexers), TweakListOptions: tweakListOptions})
}

// NewRoleInformerWithOptions constructs a new informer for Role type with additional options.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
// If you really need an independent one, prefer using the type-safe variant (see [NewTypedRoleInformerWithOptions]).
func NewRoleInformerWithOptions(client kubernetes.Interface, namespace string, options internalinterfaces.InformerOptions) cache.SharedIndexInformer {
	return NewTypedRoleInformerWithOptions(client, namespace, options)
}

// NewTypedRoleInformerWithOptions constructs a new informer for Role type with additional options.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewTypedRoleInformerWithOptions(client kubernetes.Interface, namespace string, options internalinterfaces.InformerOptions) RoleIndexInformer {
	gvr := schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "roles"}
	identifier := options.InformerName.WithResource(gvr)
	tweakListOptions := options.TweakListOptions
	return cache.NewTypedSharedIndexInformer[*apirbacv1.Role](cache.NewSharedIndexInformerWithOptions(
		cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
			ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.RbacV1().Roles(namespace).List(context.Background(), opts)
			},
			WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.RbacV1().Roles(namespace).Watch(context.Background(), opts)
			},
			ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.RbacV1().Roles(namespace).List(ctx, opts)
			},
			WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.RbacV1().Roles(namespace).Watch(ctx, opts)
			},
		}, client),
		&apirbacv1.Role{},
		cache.SharedIndexInformerOptions{
			ResyncPeriod: options.ResyncPeriod,
			Indexers:     options.Indexers,
			Identifier:   identifier,
		},
	))
}

func (f *roleInformer) defaultInformer(client kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
	return NewTypedRoleInformerWithOptions(client, f.namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, InformerName: f.factory.InformerName(), TweakListOptions: f.tweakListOptions})
}

func (f *roleInformer) Informer() cache.SharedIndexInformer {
	return f.TypedInformer()
}

func (f *roleInformer) TypedInformer() RoleIndexInformer {
	return cache.NewTypedSharedIndexInformer[*apirbacv1.Role](f.factory.InformerFor(&apirbacv1.Role{}, f.defaultInformer))
}

func (f *roleInformer) Lister() rbacv1.RoleLister {
	return rbacv1.NewRoleLister(f.Informer().GetIndexer())
}

// ToTypedRoleInformer converts an untyped informer into a TypedRoleInformer.
//
// WARNING: this conversion is only safe if the informer handles objects of type
// *Role. If that is not the case, calling type-safe methods of the returned
// TypedRoleInformer leads to runtime panics. A safer alternative is to pass
// around a TypedRoleInformer instances that was obtained from a
// SharedInformerFactory.
func ToTypedRoleInformer(informer RoleInformer) TypedRoleInformer {
	if informer, ok := informer.(TypedRoleInformer); ok {
		return informer
	}
	return &roleTypedInformerAdapter{informer}
}

type roleTypedInformerAdapter struct {
	RoleInformer
}

func (a *roleTypedInformerAdapter) TypedInformer() RoleIndexInformer {
	return cache.NewTypedSharedIndexInformer[*apirbacv1.Role](a.Informer())
}

// ToRoleIndexInformer converts an untyped informer into a RoleIndexInformer.
//
// WARNING: this conversion is only safe if the informer handles objects of type
// *Role. If that is not the case, calling type-safe methods of the returned
// RoleIndexInformer leads to runtime panics. A safer alternative is to pass
// around a RoleIndexInformer instances that was obtained from a
// SharedInformerFactory.
func ToRoleIndexInformer(informer cache.SharedIndexInformer) RoleIndexInformer {
	if informer, ok := informer.(RoleIndexInformer); ok {
		return informer
	}
	return cache.NewTypedSharedIndexInformer[*apirbacv1.Role](informer)
}
