package bootstrapimpl

import (
	"log"

	"github.com/nexuscrm/kernel/pkg/schema"
	kernelschemacatalog "github.com/nexuscrm/kernel/pkg/schemacatalog"
)

// systemTablesJSON re-exposes the embedded system-tables catalog bytes, owned by
// the kernel schemacatalog package. Kept as an in-package var so the relocated
// field-provenance init reaches the raw bytes without importing backend.
//
// This mirrors the backend bootstrap copy (both delegate to the same kernel
// catalog); the duplication exists so controlplane/bootstrapimpl needs no edge
// to backend.
var systemTablesJSON = kernelschemacatalog.SystemTablesJSON()

// GetSystemTableDefinitions returns definitions for all system tables, loaded
// from the embedded kernel catalog.
func GetSystemTableDefinitions() []schema.TableDefinition {
	defs, err := kernelschemacatalog.SystemTableDefinitions()
	if err != nil {
		log.Fatalf("Failed to parse system_tables.json: %v", err)
	}
	return defs
}

// GetManagedTableDefinitions returns substrate table definitions only.
// Application objects are owned by app packs and are not included here.
func GetManagedTableDefinitions() []schema.TableDefinition {
	defs, err := kernelschemacatalog.ManagedTableDefinitions()
	if err != nil {
		log.Fatalf("%v", err)
	}
	return defs
}
