// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you 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.

package schema

// Kind is the type of a resource.
type Kind int

// KindMask tends to check whether an event is valid.
const (
	KindGroup Kind = 1 << iota
	KindStream
	KindMeasure
	KindTrace
	KindIndexRuleBinding
	KindIndexRule
	KindTopNAggregation
	KindNode
	KindProperty
	KindMask = KindGroup | KindStream | KindMeasure | KindTrace |
		KindIndexRuleBinding | KindIndexRule |
		KindTopNAggregation | KindNode | KindProperty
	KindSize = 9
)

func (k Kind) String() string {
	switch k {
	case KindGroup:
		return "group"
	case KindStream:
		return "stream"
	case KindMeasure:
		return "measure"
	case KindTrace:
		return "trace"
	case KindIndexRuleBinding:
		return "indexRuleBinding"
	case KindIndexRule:
		return "indexRule"
	case KindTopNAggregation:
		return "topNAggregation"
	case KindNode:
		return "node"
	case KindProperty:
		return "property"
	default:
		return "unknown"
	}
}

// AllKinds returns all known Kind values.
func AllKinds() []Kind {
	var kinds []Kind
	for i := 0; i < KindSize; i++ {
		ki := Kind(1 << i)
		if KindMask&ki > 0 {
			kinds = append(kinds, ki)
		}
	}
	return kinds
}
