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

// DatadogMetricLister helps list DatadogMetrics.
type DatadogMetricLister interface {
	// List lists all DatadogMetrics in the indexer.
	List(selector labels.Selector) (ret []*v1alpha1.DatadogMetric, err error)
	// DatadogMetrics returns an object that can list and get DatadogMetrics.
	DatadogMetrics(namespace string) DatadogMetricNamespaceLister
	DatadogMetricListerExpansion
}

// datadogMetricLister implements the DatadogMetricLister interface.
type datadogMetricLister struct {
	indexer cache.Indexer
}

// NewDatadogMetricLister returns a new DatadogMetricLister.
func NewDatadogMetricLister(indexer cache.Indexer) DatadogMetricLister {
	return &datadogMetricLister{indexer: indexer}
}

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

// DatadogMetrics returns an object that can list and get DatadogMetrics.
func (s *datadogMetricLister) DatadogMetrics(namespace string) DatadogMetricNamespaceLister {
	return datadogMetricNamespaceLister{indexer: s.indexer, namespace: namespace}
}

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

// datadogMetricNamespaceLister implements the DatadogMetricNamespaceLister
// interface.
type datadogMetricNamespaceLister struct {
	indexer   cache.Indexer
	namespace string
}

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

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