/*
Copyright 2020 caicloud authors. All rights reserved.
*/

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

package v1alpha1

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

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

// stageLister implements the StageLister interface.
type stageLister struct {
	indexer cache.Indexer
}

// NewStageLister returns a new StageLister.
func NewStageLister(indexer cache.Indexer) StageLister {
	return &stageLister{indexer: indexer}
}

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

// Stages returns an object that can list and get Stages.
func (s *stageLister) Stages(namespace string) StageNamespaceLister {
	return stageNamespaceLister{indexer: s.indexer, namespace: namespace}
}

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

// stageNamespaceLister implements the StageNamespaceLister
// interface.
type stageNamespaceLister struct {
	indexer   cache.Indexer
	namespace string
}

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

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