// Copyright 2018 Istio 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 pilot/tools/generate_config_crd_types.go. DO NOT EDIT!

package crd

// This file contains Go definitions for Custom Resource Definition kinds
// to adhere to the idiomatic use of k8s API machinery.
// These definitions are synthesized from Istio configuration type descriptors
// as declared in the Pilot config model.

import (
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"

	"istio.io/istio/pilot/pkg/model"
)

type schemaType struct {
        schema     model.ProtoSchema
        object     IstioObject
        collection IstioObjectList
}

var knownTypes = map[string]schemaType{
{{range $index, $element := .}}model.{{ .IstioKind }}.Type: {
        schema: model.{{ .IstioKind }},
        object: &{{ .CrdKind }}{
            TypeMeta: meta_v1.TypeMeta{
                Kind:       "{{ .CrdKind }}",
                APIVersion: apiVersion(&model.{{ .IstioKind }}),
            },
        },
        collection: &{{ .CrdKind }}List{},
    },
{{end}}
}

{{range $index, $element := .}}
// {{ .CrdKind }} is the generic Kubernetes API object wrapper
type {{ .CrdKind }} struct {
	meta_v1.TypeMeta   `json:",inline"`
	meta_v1.ObjectMeta `json:"metadata"`
	Spec               map[string]interface{} `json:"spec"`
}

// GetSpec from a wrapper
func (in *{{ .CrdKind }}) GetSpec() map[string]interface{} {
	return in.Spec
}

// SetSpec for a wrapper
func (in *{{ .CrdKind }}) SetSpec(spec map[string]interface{}) {
	in.Spec = spec
}

// GetObjectMeta from a wrapper
func (in *{{ .CrdKind }}) GetObjectMeta() meta_v1.ObjectMeta {
	return in.ObjectMeta
}

// SetObjectMeta for a wrapper
func (in *{{ .CrdKind }}) SetObjectMeta(metadata meta_v1.ObjectMeta) {
	in.ObjectMeta = metadata
}

// {{ .CrdKind }}List is the generic Kubernetes API list wrapper
type {{ .CrdKind }}List struct {
	meta_v1.TypeMeta `json:",inline"`
	meta_v1.ListMeta `json:"metadata"`
	Items            []{{ .CrdKind }} `json:"items"`
}

// GetItems from a wrapper
func (in *{{ .CrdKind }}List) GetItems() []IstioObject {
	out := make([]IstioObject, len(in.Items))
	for i := range in.Items {
		out[i] = &in.Items[i]
	}
	return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *{{ .CrdKind }}) DeepCopyInto(out *{{ .CrdKind }}) {
	*out = *in
	out.TypeMeta = in.TypeMeta
	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
	out.Spec = in.Spec
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new {{ .CrdKind }}.
func (in *{{ .CrdKind }}) DeepCopy() *{{ .CrdKind }} {
	if in == nil {
		return nil
	}
	out := new({{ .CrdKind }})
	in.DeepCopyInto(out)
	return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *{{ .CrdKind }}) DeepCopyObject() runtime.Object {
	if c := in.DeepCopy(); c != nil {
		return c
	}

	return nil
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *{{ .CrdKind }}List) DeepCopyInto(out *{{ .CrdKind }}List) {
	*out = *in
	out.TypeMeta = in.TypeMeta
	out.ListMeta = in.ListMeta
	if in.Items != nil {
		in, out := &in.Items, &out.Items
		*out = make([]{{ .CrdKind }}, len(*in))
		for i := range *in {
			(*in)[i].DeepCopyInto(&(*out)[i])
		}
	}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new {{ .CrdKind }}List.
func (in *{{ .CrdKind }}List) DeepCopy() *{{ .CrdKind }}List {
	if in == nil {
		return nil
	}
	out := new({{ .CrdKind }}List)
	in.DeepCopyInto(out)
	return out
}

// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *{{ .CrdKind }}List) DeepCopyObject() runtime.Object {
	if c := in.DeepCopy(); c != nil {
		return c
	}

	return nil
}
{{end}}
