func (enum *EnumType) BaseType() *PrimitiveType {
	return enum.baseType
}
BaseType returns the base type of the enum
package astmodel
import (
	"fmt"
	"go/token"
	"sort"
	"strings"
	"github.com/Azure/k8s-infra/hack/generator/pkg/astbuilder"
	"github.com/dave/dst"
	"k8s.io/klog/v2"
)
type EnumType struct {
	baseType *PrimitiveType
	options []EnumValue
}
var _ Type = (*EnumType)(nil)
func NewEnumType(baseType *PrimitiveType, options ...EnumValue) *EnumType {
	if baseType == nil {
		panic("baseType must be provided")
	}
	sort.Slice(options, func(left int, right int) bool {
		return options[left].Identifier < options[right].Identifier
	})
	return &EnumType{baseType: baseType, options: options}
}
func (enum *EnumType) AsDeclarations(codeGenerationContext *CodeGenerationContext, declContext DeclarationContext) []dst.Decl {
	result := []dst.Decl{enum.createBaseDeclaration(codeGenerationContext, declContext.Name, declContext.Description, declContext.Validations)}
	var specs []dst.Spec
	for _, v := range enum.options {
		s := enum.createValueDeclaration(declContext.Name, v)
		specs = append(specs, s)
	}
	if len(specs) > 0 {
		declaration := &dst.GenDecl{
			Tok:   token.CONST,
			Specs: specs,
		}
		result = append(result, declaration)
	}
	return result
}
func (enum *EnumType) createBaseDeclaration(
	codeGenerationContext *CodeGenerationContext,
	name TypeName,
	description []string,
	validations []KubeBuilderValidation) dst.Decl {
	typeSpecification := &dst.TypeSpec{
		Name: dst.NewIdent(name.Name()),
		Type: enum.baseType.AsType(codeGenerationContext),
	}
	declaration := &dst.GenDecl{
		Decs: dst.GenDeclDecorations{
			NodeDecs: dst.NodeDecs{
				Before: dst.EmptyLine,
			},
		},
		Tok: token.TYPE,
		Specs: []dst.Spec{
			typeSpecification,
		},
	}
	astbuilder.AddWrappedComments(&declaration.Decs.Start, description, 120)
	AddValidationComments(&declaration.Decs.Start, validations)
	validationComment := GenerateKubebuilderComment(enum.CreateValidation())
	astbuilder.AddComment(&declaration.Decs.Start, validationComment)
	return declaration
}
func (enum *EnumType) createValueDeclaration(name TypeName, value EnumValue) dst.Spec {
	valueSpec := &dst.ValueSpec{
		Names: []*dst.Ident{dst.NewIdent(GetEnumValueId(name.name, value))},
		Values: []dst.Expr{
			astbuilder.CallFunc(name.Name(), astbuilder.TextLiteral(value.Value)),
		},
	}
	return valueSpec
}
func (enum *EnumType) AsType(codeGenerationContext *CodeGenerationContext) dst.Expr {
	klog.Warning("Emitting unnamed enum, something’s awry")
	return enum.baseType.AsType(codeGenerationContext)
}
func (enum *EnumType) AsZero(types Types, ctx *CodeGenerationContext) dst.Expr {
	return enum.baseType.AsZero(types, ctx)
}
func (enum *EnumType) References() TypeNameSet {
	return enum.baseType.References()
}
func (enum *EnumType) Equals(t Type) bool {
	if e, ok := t.(*EnumType); ok {
		if !enum.baseType.Equals(e.baseType) {
			return false
		}
		if len(enum.options) != len(e.options) {
			return false
		}
		for i := range enum.options {
			if !enum.options[i].Equals(&e.options[i]) {
				return false
			}
		}
		return true
	}
	return false
}
func (enum *EnumType) RequiredPackageReferences() *PackageReferenceSet {
	return NewPackageReferenceSet()
}
func (enum *EnumType) Options() []EnumValue {
	return append(enum.options[:0:0], enum.options...)
}
func (enum *EnumType) CreateValidation() KubeBuilderValidation {
	var values []interface{}
	for _, opt := range enum.Options() {
		values = append(values, opt.Value)
	}
	return ValidateEnum(values)
}