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

package v1alpha1

import (
	v1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/client-go/tools/cache"
)

// OverridePolicyLister helps list OverridePolicies.
// All objects returned here must be treated as read-only.
type OverridePolicyLister interface {
	// List lists all OverridePolicies in the indexer.
	// Objects returned here must be treated as read-only.
	List(selector labels.Selector) (ret []*v1alpha1.OverridePolicy, err error)
	// OverridePolicies returns an object that can list and get OverridePolicies.
	OverridePolicies(namespace string) OverridePolicyNamespaceLister
	OverridePolicyListerExpansion
}

// overridePolicyLister implements the OverridePolicyLister interface.
type overridePolicyLister struct {
	indexer cache.Indexer
}

// NewOverridePolicyLister returns a new OverridePolicyLister.
func NewOverridePolicyLister(indexer cache.Indexer) OverridePolicyLister {
	return &overridePolicyLister{indexer: indexer}
}

// List lists all OverridePolicies in the indexer.
func (s *overridePolicyLister) List(selector labels.Selector) (ret []*v1alpha1.OverridePolicy, err error) {
	err = cache.ListAll(s.indexer, selector, func(m interface{}) {
		ret = append(ret, m.(*v1alpha1.OverridePolicy))
	})
	return ret, err
}

// OverridePolicies returns an object that can list and get OverridePolicies.
func (s *overridePolicyLister) OverridePolicies(namespace string) OverridePolicyNamespaceLister {
	return overridePolicyNamespaceLister{indexer: s.indexer, namespace: namespace}
}

// OverridePolicyNamespaceLister helps list and get OverridePolicies.
// All objects returned here must be treated as read-only.
type OverridePolicyNamespaceLister interface {
	// List lists all OverridePolicies in the indexer for a given namespace.
	// Objects returned here must be treated as read-only.
	List(selector labels.Selector) (ret []*v1alpha1.OverridePolicy, err error)
	// Get retrieves the OverridePolicy from the indexer for a given namespace and name.
	// Objects returned here must be treated as read-only.
	Get(name string) (*v1alpha1.OverridePolicy, error)
	OverridePolicyNamespaceListerExpansion
}

// overridePolicyNamespaceLister implements the OverridePolicyNamespaceLister
// interface.
type overridePolicyNamespaceLister struct {
	indexer   cache.Indexer
	namespace string
}

// List lists all OverridePolicies in the indexer for a given namespace.
func (s overridePolicyNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.OverridePolicy, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1alpha1.OverridePolicy))
	})
	return ret, err
}

// Get retrieves the OverridePolicy from the indexer for a given namespace and name.
func (s overridePolicyNamespaceLister) Get(name string) (*v1alpha1.OverridePolicy, error) {
	obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
	if err != nil {
		return nil, err
	}
	if !exists {
		return nil, errors.NewNotFound(v1alpha1.Resource("overridepolicy"), name)
	}
	return obj.(*v1alpha1.OverridePolicy), nil
}
