/*
Copyright 2020 Authors of Arktos.

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 lister-gen. DO NOT EDIT.

package v1

import (
	v1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/client-go/tools/cache"
)

// ActionLister helps list Actions.
type ActionLister interface {
	// List lists all Actions in the indexer.
	List(selector labels.Selector) (ret []*v1.Action, err error)
	// Actions returns an object that can list and get Actions.
	Actions(namespace string) ActionNamespaceLister
	ActionsWithMultiTenancy(namespace string, tenant string) ActionNamespaceLister
	ActionListerExpansion
}

// actionLister implements the ActionLister interface.
type actionLister struct {
	indexer cache.Indexer
}

// NewActionLister returns a new ActionLister.
func NewActionLister(indexer cache.Indexer) ActionLister {
	return &actionLister{indexer: indexer}
}

// List lists all Actions in the indexer.
func (s *actionLister) List(selector labels.Selector) (ret []*v1.Action, err error) {
	err = cache.ListAll(s.indexer, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.Action))
	})
	return ret, err
}

// Actions returns an object that can list and get Actions.
func (s *actionLister) Actions(namespace string) ActionNamespaceLister {
	return actionNamespaceLister{indexer: s.indexer, namespace: namespace, tenant: "system"}
}

func (s *actionLister) ActionsWithMultiTenancy(namespace string, tenant string) ActionNamespaceLister {
	return actionNamespaceLister{indexer: s.indexer, namespace: namespace, tenant: tenant}
}

// ActionNamespaceLister helps list and get Actions.
type ActionNamespaceLister interface {
	// List lists all Actions in the indexer for a given tenant/namespace.
	List(selector labels.Selector) (ret []*v1.Action, err error)
	// Get retrieves the Action from the indexer for a given tenant/namespace and name.
	Get(name string) (*v1.Action, error)
	ActionNamespaceListerExpansion
}

// actionNamespaceLister implements the ActionNamespaceLister
// interface.
type actionNamespaceLister struct {
	indexer   cache.Indexer
	namespace string
	tenant    string
}

// List lists all Actions in the indexer for a given namespace.
func (s actionNamespaceLister) List(selector labels.Selector) (ret []*v1.Action, err error) {
	err = cache.ListAllByNamespace(s.indexer, s.tenant, s.namespace, selector, func(m interface{}) {
		ret = append(ret, m.(*v1.Action))
	})
	return ret, err
}

// Get retrieves the Action from the indexer for a given namespace and name.
func (s actionNamespaceLister) Get(name string) (*v1.Action, error) {
	key := s.tenant + "/" + s.namespace + "/" + name
	if s.tenant == "system" {
		key = s.namespace + "/" + name
	}
	obj, exists, err := s.indexer.GetByKey(key)
	if err != nil {
		return nil, err
	}
	if !exists {
		return nil, errors.NewNotFound(v1.Resource("action"), name)
	}
	return obj.(*v1.Action), nil
}
