package constants

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

func TestIsSystemTable(t *testing.T) {
	tests := []struct {
		tableName string
		want      bool
	}{
		{TableObject, true},
		{TableField, true},
		{TableUser, false},
		{"_System_Custom", true}, // Tests prefix detection for any _System_ table
		{"Custom_Object", false},
		{"User", false},
		{"system_lower", false},
		{"", false},
	}

	for _, tt := range tests {
		t.Run(tt.tableName, func(t *testing.T) {
			if got := IsSystemTable(tt.tableName); got != tt.want {
				t.Errorf("IsSystemTable(%q) = %v, want %v", tt.tableName, got, tt.want)
			}
		})
	}
}

func TestScopeFloorDocumentsManagedTables(t *testing.T) {
	path := filepath.Join("..", "..", "..", "docs", "design", "scope-floor.md")
	data, err := os.ReadFile(path)
	if err != nil {
		t.Fatalf("read scope floor %s: %v", path, err)
	}
	text := string(data)
	for _, tableName := range AllSystemTableNames {
		if !strings.Contains(text, "`"+tableName+"`") {
			t.Fatalf("scope floor %s does not document managed table %q; Table* generation must not amend the floor by side effect", path, tableName)
		}
	}
}
