//
// Code generated by grafana-app-sdk. DO NOT EDIT.
//

package v4

import (
	"errors"

	"github.com/grafana/grafana-app-sdk/resource"
)

// schema is unexported to prevent accidental overwrites
var (
	schemaTestKind = resource.NewSimpleSchema("testapp.ext.grafana.app", "v4", NewTestKind(), &TestKindList{}, resource.WithKind("TestKind"),
		resource.WithPlural("testkinds"), resource.WithScope(resource.NamespacedScope), resource.WithSelectableFields([]resource.SelectableField{resource.SelectableField{
			FieldSelector: ".spec.union.spec.name",
			FieldValueFunc: func(o resource.Object) (string, error) {
				cast, ok := o.(*TestKind)
				if !ok {
					return "", errors.New("provided object must be of type *TestKind")
				}
				if cast.Spec.Union.UnionVariantA != nil {
					return string(cast.Spec.Union.UnionVariantA.Spec.Name), nil
				}
				if cast.Spec.Union.UnionVariantB != nil {
					return string(cast.Spec.Union.UnionVariantB.Spec.Name), nil
				}
				return "", nil
			},
		},
		}))
	kindTestKind = resource.Kind{
		Schema: schemaTestKind,
		Codecs: map[resource.KindEncoding]resource.Codec{
			resource.KindEncodingJSON: &TestKindJSONCodec{},
		},
	}
)

// Kind returns a resource.Kind for this Schema with a JSON codec
func TestKindKind() resource.Kind {
	return kindTestKind
}

// Schema returns a resource.SimpleSchema representation of TestKind
func TestKindSchema() *resource.SimpleSchema {
	return schemaTestKind
}

// Interface compliance checks
var _ resource.Schema = kindTestKind
