// Copyright Contributors to the KubeOpenCode project

// Package v1alpha1 contains API Schema definitions for the kubeopencode v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=kubeopencode.io
package v1alpha1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
	// GroupName is the group name for the kubeopencode API
	GroupName = "kubeopencode.io"
	// GroupVersion is group version used to register these objects
	GroupVersion  = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
	schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
	// Install is a function which adds this version to a scheme
	Install = schemeBuilder.AddToScheme

	// SchemeGroupVersion generated code relies on this name
	// Deprecated
	SchemeGroupVersion = GroupVersion
	// AddToScheme exists solely to keep the old generators creating valid code
	// DEPRECATED
	AddToScheme = schemeBuilder.AddToScheme
)

// Resource generated code relies on this being here, but it logically belongs to the group
// DEPRECATED
func Resource(resource string) schema.GroupResource {
	return schema.GroupResource{Group: GroupName, Resource: resource}
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
	scheme.AddKnownTypes(GroupVersion,
		&Task{},
		&TaskList{},
		&CronTask{},
		&CronTaskList{},
		&Agent{},
		&AgentList{},
		&AgentTemplate{},
		&AgentTemplateList{},
		&KubeOpenCodeConfig{},
		&KubeOpenCodeConfigList{},
		&Registry{},
		&RegistryList{},
	)
	metav1.AddToGroupVersion(scheme, GroupVersion)
	return nil
}
