package packs

import "testing"

// TestBootstrapSeeds_PreservesLegacySource is the regression guard for
// Codex Round-5 V1-P1 / V2-C1: the previous phase5 wire-up stripped
// LegacySource via a 5-column SELECT. BootstrapSeeds MUST preserve
// every row's LegacySource verbatim so BuildScopeSourceMapFromSeeds
// emits the correct scope-source map.
//
// Per issue #1609 BootstrapSeeds returns standard seeds only; tenant
// autonumber formats are applied by `cmd/setup apply-tenant` against
// controlplane/tenants/<tenant>/autonumber_formats.go and are verified
// in the tenant package's own tests.
func TestBootstrapSeeds_PreservesLegacySource(t *testing.T) {
	got := BootstrapSeeds()
	want := len(AutoNumberFormatSeeds)
	if len(got) != want {
		t.Fatalf("BootstrapSeeds len: got %d, want %d (standard only)", len(got), want)
	}
	for i, s := range AutoNumberFormatSeeds {
		if got[i].ObjectName != s.ObjectName {
			t.Errorf("row %d ObjectName: got %q, want %q",
				i, got[i].ObjectName, s.ObjectName)
		}
		if got[i].FieldApiName != s.FieldApiName {
			t.Errorf("row %d FieldApiName: got %q, want %q",
				i, got[i].FieldApiName, s.FieldApiName)
		}
		if got[i].Format != s.Format {
			t.Errorf("row %d Format: got %q, want %q",
				i, got[i].Format, s.Format)
		}
		if got[i].Scope != s.Scope {
			t.Errorf("row %d Scope: got %q, want %q",
				i, got[i].Scope, s.Scope)
		}
		if got[i].Start != s.Start {
			t.Errorf("row %d Start: got %d, want %d",
				i, got[i].Start, s.Start)
		}
		if got[i].LegacySource != s.LegacySource {
			t.Errorf("row %d %s.%s LegacySource: got %q, want %q",
				i, s.ObjectName, s.FieldApiName,
				got[i].LegacySource, s.LegacySource)
		}
	}
}

// TestBootstrapSeeds_AllLegacySourcesNonEmpty pins the data-spec
// invariant that every seeded field declares a LegacySource — no
// regression to silent "none" defaulting. If a net-new admin-created
// autonumber is added that legitimately has no legacy counter, it
// should declare LegacySource="none" explicitly.
func TestBootstrapSeeds_AllLegacySourcesNonEmpty(t *testing.T) {
	for _, s := range BootstrapSeeds() {
		if s.LegacySource == "" {
			t.Errorf("%s.%s has empty LegacySource — spec requires an explicit value (including \"none\")",
				s.ObjectName, s.FieldApiName)
		}
	}
}
