package bootstrap

import (
	"os"
	"strings"
	"testing"
)

// Anti-regrowth seal for L0-E PR-1.
//
// api_contracts.json is the source of truth that the frontend/Go contract
// generators (cmd/codegen) read to (re)generate shared/pkg/api/dtos.go and
// frontend/src/generated/api.ts. Five Salesforce-shaped REST DTOs
// (UserDTO, LoginRequest, LoginResponse, PermissionSetDTO, and the api-package
// SearchResult) were deleted as dead wire-shape from the app-blind surface.
//
// Because regeneration reads this file, leaving (or re-adding) a definition
// here would silently resurrect the deleted DTOs on the next regen. This test
// pins their absence so the class cannot regrow through the load-bearing
// source-of-truth vector.
//
// The companion arm (no PascalCase-first json tag in shared/pkg/api/*.go) lives
// in the shared module, which can scan its own package files without a
// cross-module path under GOWORK=off.
func TestAPIContractsHasNoResurrectedDeadDTOs(t *testing.T) {
	// Test cwd is the package directory, so the JSON sits alongside this file.
	const contractsFile = "api_contracts.json"

	data, err := os.ReadFile(contractsFile)
	if err != nil {
		t.Fatalf("read %s: %v", contractsFile, err)
	}
	contents := string(data)

	// These are the exact "name" values of the removed contract definitions.
	// They are matched as quoted contract names so we only trip on a real
	// definition entry, not an incidental substring elsewhere.
	removed := []string{
		"UserDTO",
		"LoginRequest",
		"LoginResponse",
		"PermissionSetDTO",
		"SearchResult",
	}
	for _, name := range removed {
		needle := "\"" + name + "\""
		if strings.Contains(contents, needle) {
			t.Errorf("%s must not declare the removed dead DTO %q; "+
				"regeneration reads this file and would resurrect it. "+
				"See L0-E PR-1.", contractsFile, name)
		}
	}
}
