package zddc

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

// TestIsAutoOwnPath / TestIsWormPath / TestWormFolderLevelIndex /
// TestWormMaskStripsWDA retired in the cascade-config migration. The
// `auto_own:` and `worm:` .zddc keys carry these conventions now —
// see lookups_test.go (AutoOwnAt) and worm_test.go (WormZoneGrant);
// the canonical defaults live in defaults.zddc.yaml.

func TestResolveCanonicalCaseFold(t *testing.T) {
	dir := t.TempDir()
	if err := os.MkdirAll(filepath.Join(dir, "Working"), 0o755); err != nil {
		t.Fatal(err)
	}
	if err := os.MkdirAll(filepath.Join(dir, "ARCHIVE"), 0o755); err != nil {
		t.Fatal(err)
	}
	// A regular file with a canonical name must NOT be returned (we only resolve directories).
	if err := os.WriteFile(filepath.Join(dir, "staging"), []byte{}, 0o644); err != nil {
		t.Fatal(err)
	}

	cases := map[string]string{
		"working":   "Working", // PascalCase wins because it exists on disk
		"WORKING":   "Working",
		"Working":   "Working",
		"archive":   "ARCHIVE",
		"reviewing": "", // not present
		"staging":   "", // present as a file, not a directory — must skip
	}
	for logical, want := range cases {
		got, err := ResolveCanonical(dir, logical)
		if err != nil {
			t.Errorf("ResolveCanonical(%q): %v", logical, err)
			continue
		}
		if got != want {
			t.Errorf("ResolveCanonical(%q) = %q, want %q", logical, got, want)
		}
	}
}

func TestResolveCanonicalMissingParent(t *testing.T) {
	got, err := ResolveCanonical(filepath.Join(t.TempDir(), "does-not-exist"), "working")
	if err != nil {
		t.Errorf("expected nil error for missing parent, got %v", err)
	}
	if got != "" {
		t.Errorf("expected empty result for missing parent, got %q", got)
	}
}

// TestCanonicalLists and TestIsProjectRootFolder retired in Phase 3 —
// the canonical convention is now expressed in defaults.zddc.yaml and
// asserted by lookups_test.go (TestDefaultToolAt_FromEmbeddedConvention,
// TestIsDeclaredPath_FromEmbeddedConvention, etc.).
