/*
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 v1beta1

import (
	context "context"
	time "time"

	apicoordinationv1beta1 "k8s.io/api/coordination/v1beta1"
	v1 "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"
	coordinationv1beta1 "k8s.io/client-go/listers/coordination/v1beta1"
	cache "k8s.io/client-go/tools/cache"
)

// LeaseInformer provides access to a shared informer and lister for
// Leases. Prefer using the type-safe variant (see [TypedLeaseInformer]).
type LeaseInformer interface {
	Informer() cache.SharedIndexInformer
	Lister() coordinationv1beta1.LeaseLister
}

// TypedLeaseInformer provides access to a shared informer and lister for
// Leases, including the type-safe TypedInformer variant.
// It is a superset of LeaseInformer.
type TypedLeaseInformer interface {
	Informer() cache.SharedIndexInformer
	TypedInformer() LeaseIndexInformer
	Lister() coordinationv1beta1.LeaseLister
}

// LeaseIndexInformer is a wrapper around the underlying [cache.SharedIndexInformer]
// with type-safe variants of several methods.
type LeaseIndexInformer cache.TypedSharedIndexInformer[*apicoordinationv1beta1.Lease]

// LeaseHandlerFuncs is a specialization of [cache.TypedResourceEventHandlerFuncs] for Lease.
type LeaseHandlerFuncs = cache.TypedResourceEventHandlerFuncs[*apicoordinationv1beta1.Lease]

// LeaseDetailedHandlerFuncs is a specialization of [cache.TypedResourceEventHandlerDetailedFuncs] for Lease.
type LeaseDetailedHandlerFuncs = cache.TypedResourceEventHandlerDetailedFuncs[*apicoordinationv1beta1.Lease]

// LeaseFilteringHandler is a specialization of [cache.TypedFilteringResourceEventHandler] for Lease.
type LeaseFilteringHandler = cache.TypedFilteringResourceEventHandler[*apicoordinationv1beta1.Lease]

// LeaseIndexers is a specialization of [cache.TypedIndexers] for Lease.
type LeaseIndexers = cache.TypedIndexers[*apicoordinationv1beta1.Lease]

// DeletedLease is a specialization of [cache.DeletedObject] for Lease.
type DeletedLease = cache.DeletedObject[*apicoordinationv1beta1.Lease]

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

// NewLeaseInformer constructs a new informer for Lease 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 [NewTypedLeaseInformer]).
func NewLeaseInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
	return NewLeaseInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: indexers})
}

// NewTypedLeaseInformer constructs a new informer for Lease 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 NewTypedLeaseInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers LeaseIndexers) LeaseIndexInformer {
	return NewTypedLeaseInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: cache.TypedIndexersToIndexers(indexers)})
}

// NewFilteredLeaseInformer constructs a new informer for Lease 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 [NewTypedFilteredLeaseInformer]).
func NewFilteredLeaseInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
	return NewTypedLeaseInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: indexers, TweakListOptions: tweakListOptions})
}

// NewTypedFilteredLeaseInformer constructs a new informer for Lease 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 NewTypedFilteredLeaseInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers LeaseIndexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) LeaseIndexInformer {
	return NewTypedLeaseInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: cache.TypedIndexersToIndexers(indexers), TweakListOptions: tweakListOptions})
}

// NewLeaseInformerWithOptions constructs a new informer for Lease 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 [NewTypedLeaseInformerWithOptions]).
func NewLeaseInformerWithOptions(client kubernetes.Interface, namespace string, options internalinterfaces.InformerOptions) cache.SharedIndexInformer {
	return NewTypedLeaseInformerWithOptions(client, namespace, options)
}

// NewTypedLeaseInformerWithOptions constructs a new informer for Lease 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 NewTypedLeaseInformerWithOptions(client kubernetes.Interface, namespace string, options internalinterfaces.InformerOptions) LeaseIndexInformer {
	gvr := schema.GroupVersionResource{Group: "coordination.k8s.io", Version: "v1beta1", Resource: "leases"}
	identifier := options.InformerName.WithResource(gvr)
	tweakListOptions := options.TweakListOptions
	return cache.NewTypedSharedIndexInformer[*apicoordinationv1beta1.Lease](cache.NewSharedIndexInformerWithOptions(
		cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
			ListFunc: func(opts v1.ListOptions) (runtime.Object, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.CoordinationV1beta1().Leases(namespace).List(context.Background(), opts)
			},
			WatchFunc: func(opts v1.ListOptions) (watch.Interface, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.CoordinationV1beta1().Leases(namespace).Watch(context.Background(), opts)
			},
			ListWithContextFunc: func(ctx context.Context, opts v1.ListOptions) (runtime.Object, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.CoordinationV1beta1().Leases(namespace).List(ctx, opts)
			},
			WatchFuncWithContext: func(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
				if tweakListOptions != nil {
					tweakListOptions(&opts)
				}
				return client.CoordinationV1beta1().Leases(namespace).Watch(ctx, opts)
			},
		}, client),
		&apicoordinationv1beta1.Lease{},
		cache.SharedIndexInformerOptions{
			ResyncPeriod: options.ResyncPeriod,
			Indexers:     options.Indexers,
			Identifier:   identifier,
		},
	))
}

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

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

func (f *leaseInformer) TypedInformer() LeaseIndexInformer {
	return cache.NewTypedSharedIndexInformer[*apicoordinationv1beta1.Lease](f.factory.InformerFor(&apicoordinationv1beta1.Lease{}, f.defaultInformer))
}

func (f *leaseInformer) Lister() coordinationv1beta1.LeaseLister {
	return coordinationv1beta1.NewLeaseLister(f.Informer().GetIndexer())
}

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

type leaseTypedInformerAdapter struct {
	LeaseInformer
}

func (a *leaseTypedInformerAdapter) TypedInformer() LeaseIndexInformer {
	return cache.NewTypedSharedIndexInformer[*apicoordinationv1beta1.Lease](a.Informer())
}

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