package bootstrapimpl

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

func TestSchemaReadinessStaysOutOfSchemaGodFile(t *testing.T) {
	root := "."
	schemaSrc := readBootstrapSourceForStructure(t, root, "schema.go")
	readinessSrc := readBootstrapSourceForStructure(t, root, "schema_readiness.go")

	for _, symbol := range []string{
		"func VerifySchemaReadiness(",
		"func verifyCriticalManagedColumns(",
	} {
		if strings.Contains(schemaSrc, symbol) {
			t.Fatalf("schema.go still owns readiness symbol %q", symbol)
		}
		if !strings.Contains(readinessSrc, symbol) {
			t.Fatalf("schema_readiness.go is missing readiness symbol %q", symbol)
		}
	}

	if strings.Contains(readinessSrc, "VerifyConnectedDeliverySchema(") || strings.Contains(readinessSrc, "verifyConnectedDeliverySchema(") {
		t.Fatal("pod schema readiness must not gate on dormant connected-delivery schema")
	}
}

func readBootstrapSourceForStructure(t *testing.T, root string, name string) string {
	t.Helper()
	path := filepath.Join(root, name)
	data, err := os.ReadFile(path)
	if err != nil {
		t.Fatalf("read %s: %v", path, err)
	}
	return string(data)
}
