/*
 * Copyright 2019 The original author or 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 informer-gen. DO NOT EDIT.

package externalversions

import (
	"fmt"

	v1alpha1 "github.com/pivotal/kpack/pkg/apis/build/v1alpha1"
	v1alpha2 "github.com/pivotal/kpack/pkg/apis/build/v1alpha2"
	schema "k8s.io/apimachinery/pkg/runtime/schema"
	cache "k8s.io/client-go/tools/cache"
)

// GenericInformer is type of SharedIndexInformer which will locate and delegate to other
// sharedInformers based on type
type GenericInformer interface {
	Informer() cache.SharedIndexInformer
	Lister() cache.GenericLister
}

type genericInformer struct {
	informer cache.SharedIndexInformer
	resource schema.GroupResource
}

// Informer returns the SharedIndexInformer.
func (f *genericInformer) Informer() cache.SharedIndexInformer {
	return f.informer
}

// Lister returns the GenericLister.
func (f *genericInformer) Lister() cache.GenericLister {
	return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
}

// ForResource gives generic access to a shared informer of the matching type
// TODO extend this to unknown resources with a client pool
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
	switch resource {
	// Group=kpack.io, Version=v1alpha1
	case v1alpha1.SchemeGroupVersion.WithResource("builds"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha1().Builds().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("builders"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha1().Builders().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("clusterbuilders"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha1().ClusterBuilders().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("clusterstacks"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha1().ClusterStacks().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("clusterstores"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha1().ClusterStores().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("images"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha1().Images().Informer()}, nil
	case v1alpha1.SchemeGroupVersion.WithResource("sourceresolvers"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha1().SourceResolvers().Informer()}, nil

		// Group=kpack.io, Version=v1alpha2
	case v1alpha2.SchemeGroupVersion.WithResource("builds"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().Builds().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("builders"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().Builders().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("buildpacks"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().Buildpacks().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("clusterbuilders"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().ClusterBuilders().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("clusterbuildpacks"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().ClusterBuildpacks().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("clusterlifecycles"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().ClusterLifecycles().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("clusterstacks"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().ClusterStacks().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("clusterstores"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().ClusterStores().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("images"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().Images().Informer()}, nil
	case v1alpha2.SchemeGroupVersion.WithResource("sourceresolvers"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Kpack().V1alpha2().SourceResolvers().Informer()}, nil

	}

	return nil, fmt.Errorf("no informer found for %v", resource)
}
