// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2019 Datadog, Inc.

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

package v1alpha1

import (
	v1alpha1 "github.com/DataDog/datadog-operator/pkg/apis/datadoghq/v1alpha1"
	"k8s.io/apimachinery/pkg/api/errors"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/client-go/tools/cache"
)

// DatadogAgentLister helps list DatadogAgents.
type DatadogAgentLister interface {
	// List lists all DatadogAgents in the indexer.
	List(selector labels.Selector) (ret []*v1alpha1.DatadogAgent, err error)
	// DatadogAgents returns an object that can list and get DatadogAgents.
	DatadogAgents(namespace string) DatadogAgentNamespaceLister
	DatadogAgentListerExpansion
}

// datadogAgentLister implements the DatadogAgentLister interface.
type datadogAgentLister struct {
	indexer cache.Indexer
}

// NewDatadogAgentLister returns a new DatadogAgentLister.
func NewDatadogAgentLister(indexer cache.Indexer) DatadogAgentLister {
	return &datadogAgentLister{indexer: indexer}
}

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

// DatadogAgents returns an object that can list and get DatadogAgents.
func (s *datadogAgentLister) DatadogAgents(namespace string) DatadogAgentNamespaceLister {
	return datadogAgentNamespaceLister{indexer: s.indexer, namespace: namespace}
}

// DatadogAgentNamespaceLister helps list and get DatadogAgents.
type DatadogAgentNamespaceLister interface {
	// List lists all DatadogAgents in the indexer for a given namespace.
	List(selector labels.Selector) (ret []*v1alpha1.DatadogAgent, err error)
	// Get retrieves the DatadogAgent from the indexer for a given namespace and name.
	Get(name string) (*v1alpha1.DatadogAgent, error)
	DatadogAgentNamespaceListerExpansion
}

// datadogAgentNamespaceLister implements the DatadogAgentNamespaceLister
// interface.
type datadogAgentNamespaceLister struct {
	indexer   cache.Indexer
	namespace string
}

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

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