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

	apieventsv1beta1 "k8s.io/api/events/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"
	eventsv1beta1 "k8s.io/client-go/listers/events/v1beta1"
	cache "k8s.io/client-go/tools/cache"
)

// EventInformer provides access to a shared informer and lister for
// Events. Prefer using the type-safe variant (see [TypedEventInformer]).
type EventInformer interface {
	Informer() cache.SharedIndexInformer
	Lister() eventsv1beta1.EventLister
}

// TypedEventInformer provides access to a shared informer and lister for
// Events, including the type-safe TypedInformer variant.
// It is a superset of EventInformer.
type TypedEventInformer interface {
	Informer() cache.SharedIndexInformer
	TypedInformer() EventIndexInformer
	Lister() eventsv1beta1.EventLister
}

// EventIndexInformer is a wrapper around the underlying [cache.SharedIndexInformer]
// with type-safe variants of several methods.
type EventIndexInformer cache.TypedSharedIndexInformer[*apieventsv1beta1.Event]

// EventHandlerFuncs is a specialization of [cache.TypedResourceEventHandlerFuncs] for Event.
type EventHandlerFuncs = cache.TypedResourceEventHandlerFuncs[*apieventsv1beta1.Event]

// EventDetailedHandlerFuncs is a specialization of [cache.TypedResourceEventHandlerDetailedFuncs] for Event.
type EventDetailedHandlerFuncs = cache.TypedResourceEventHandlerDetailedFuncs[*apieventsv1beta1.Event]

// EventFilteringHandler is a specialization of [cache.TypedFilteringResourceEventHandler] for Event.
type EventFilteringHandler = cache.TypedFilteringResourceEventHandler[*apieventsv1beta1.Event]

// EventIndexers is a specialization of [cache.TypedIndexers] for Event.
type EventIndexers = cache.TypedIndexers[*apieventsv1beta1.Event]

// DeletedEvent is a specialization of [cache.DeletedObject] for Event.
type DeletedEvent = cache.DeletedObject[*apieventsv1beta1.Event]

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

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

// NewTypedEventInformer constructs a new informer for Event 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 NewTypedEventInformer(client kubernetes.Interface, namespace string, resyncPeriod time.Duration, indexers EventIndexers) EventIndexInformer {
	return NewTypedEventInformerWithOptions(client, namespace, internalinterfaces.InformerOptions{ResyncPeriod: resyncPeriod, Indexers: cache.TypedIndexersToIndexers(indexers)})
}

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

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

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

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

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

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

func (f *eventInformer) TypedInformer() EventIndexInformer {
	return cache.NewTypedSharedIndexInformer[*apieventsv1beta1.Event](f.factory.InformerFor(&apieventsv1beta1.Event{}, f.defaultInformer))
}

func (f *eventInformer) Lister() eventsv1beta1.EventLister {
	return eventsv1beta1.NewEventLister(f.Informer().GetIndexer())
}

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

type eventTypedInformerAdapter struct {
	EventInformer
}

func (a *eventTypedInformerAdapter) TypedInformer() EventIndexInformer {
	return cache.NewTypedSharedIndexInformer[*apieventsv1beta1.Event](a.Informer())
}

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