/*
Copyright The Kubernetes Authors.

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 "github.com/kyverno/kyverno/api/kyverno/v1"
	"k8s.io/apimachinery/pkg/labels"
)

//ListResources is a wrapper to List and adds the resource kind information
// as the lister is specific to a gvk we can harcode the values here
func (pl *clusterPolicyLister) ListResources(selector labels.Selector) (ret []*v1.ClusterPolicy, err error) {
	policies, err := pl.List(selector)
	for index := range policies {
		policies[index].SetGroupVersionKind(v1.SchemeGroupVersion.WithKind("ClusterPolicy"))
	}
	return policies, err
}

func (s generateRequestNamespaceLister) GetGenerateRequestsForResource(kind, namespace, name string) ([]*v1.GenerateRequest, error) {
	var list []*v1.GenerateRequest
	grs, err := s.List(labels.NewSelector())
	if err != nil {
		return nil, err
	}
	for idx, gr := range grs {
		if gr.Spec.Resource.Kind == kind &&
			gr.Spec.Resource.Namespace == namespace &&
			gr.Spec.Resource.Name == name {
			list = append(list, grs[idx])

		}
	}
	return list, err
}

func (s generateRequestNamespaceLister) GetGenerateRequestsForClusterPolicy(policy string) ([]*v1.GenerateRequest, error) {
	var list []*v1.GenerateRequest
	grs, err := s.List(labels.NewSelector())
	if err != nil {
		return nil, err
	}
	for idx, gr := range grs {
		if gr.Spec.Policy == policy {
			list = append(list, grs[idx])
		}
	}
	return list, err
}
