// Code generated by pkg/config/schema/codegen/tools/collections.main.go. DO NOT EDIT.

package {{.PackageName}}

import (
	"k8s.io/apimachinery/pkg/runtime/schema"
	"istio.io/istio/pkg/config"
	"istio.io/istio/pkg/config/schema/gvr"
	"istio.io/istio/pkg/config/schema/kind"
)

var (
{{- range $entry := .Entries }}
	{{$entry.Resource.Identifier}} = config.GroupVersionKind{Group: "{{$entry.Resource.Group}}", Version: "{{$entry.Resource.Version}}", Kind: "{{$entry.Resource.Kind}}"}
	{{- range $alias := .Resource.VersionAliases }}
	{{$entry.Resource.Identifier}}_{{$alias}} = config.GroupVersionKind{Group: "{{$entry.Resource.Group}}", Version: "{{$alias}}", Kind: "{{$entry.Resource.Kind}}"}
    {{- end }}
{{- end }}
)

// ToGVR converts a GVK to a GVR.
func ToGVR(g config.GroupVersionKind) (schema.GroupVersionResource, bool) {
	switch g {
{{- range $entry := .Entries }}
		case {{$entry.Resource.Identifier}}:
			return gvr.{{$entry.Resource.Identifier}}, true
	{{- range $alias := .Resource.VersionAliases }}
		case {{$entry.Resource.Identifier}}_{{$alias}}:
			return gvr.{{$entry.Resource.Identifier}}_{{$alias}}, true
    {{- end }}
{{- end }}
	}

	return schema.GroupVersionResource{}, false
}

func ToKind(g config.GroupVersionKind) (kind.Kind, bool) {
	switch g {
{{- range .Entries }}
	{{- if not (or (eq .Resource.Identifier "Address") (eq .Resource.Identifier "DNSName")) }}
		case {{.Resource.Identifier}}:
			return kind.{{.Resource.Identifier}}, true
	{{- end }}
{{- end }}
	}

	return kind.Unknown, false
}

func MustToKind(g config.GroupVersionKind) kind.Kind {
	r, ok := ToKind(g)
	if !ok {
		panic("unknown kind: " + g.String())
	}
	return r
}

// MustToGVR converts a GVK to a GVR, and panics if it cannot be converted
// Warning: this is only safe for known types; do not call on arbitrary GVKs
func MustToGVR(g config.GroupVersionKind) schema.GroupVersionResource {
	r, ok := ToGVR(g)
	if !ok {
		panic("unknown kind: " + g.String())
	}
	return r
}

// FromGVR converts a GVR to a GVK.
func FromGVR(g schema.GroupVersionResource) (config.GroupVersionKind, bool) {
	switch g {
{{- range .Entries }}
		case gvr.{{.Resource.Identifier}}:
			return {{.Resource.Identifier}}, true
{{- end }}
	}

	return config.GroupVersionKind{}, false
}

// FromGVR converts a GVR to a GVK, and panics if it cannot be converted
// Warning: this is only safe for known types; do not call on arbitrary GVRs
func MustFromGVR(g schema.GroupVersionResource) config.GroupVersionKind {
	r, ok := FromGVR(g)
	if !ok {
		panic("unknown kind: " + g.String())
	}
	return r
}
