package utils

import (
	"testing"
)

func TestStripMountPoint(t *testing.T) {
	tests := []struct {
		name     string
		input    string
		expected string
	}{
		// macOS
		{"macOS volume", "/Volumes/ExternalDrive/Audio", "ExternalDrive/Audio"},
		{"macOS root volume", "/Volumes/Drive", "Drive"},

		// Linux /media/ with username
		{"Linux media mount", "/media/david/USB-Drive/Audio", "USB-Drive/Audio"},
		{"Linux media different user", "/media/john/Backup/Audio", "Backup/Audio"},
		{"Linux media Pomona", "/media/david/Pomona-4/Pomona/A05/2025-11-08", "Pomona-4/Pomona/A05/2025-11-08"},

		// Linux /mnt/
		{"Linux mnt mount", "/mnt/storage/Audio", "storage/Audio"},

		// No mount point
		{"Absolute no mount", "/home/user/Audio", "/home/user/Audio"},
		{"Relative path", "./relative/path", "relative/path"},

		// Edge cases
		{"Root", "/", "/"},
		{"Empty", "", "."},
		{"Volumes only", "/Volumes/", "."},
		{"Media with user only", "/media/david/", "."},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := StripMountPoint(tt.input)
			if result != tt.expected {
				t.Errorf("StripMountPoint(%q) = %q, want %q", tt.input, result, tt.expected)
			}
		})
	}
}

func TestNormalizeFolderPath(t *testing.T) {
	tests := []struct {
		name     string
		input    string
		expected string
	}{
		// Full workflow
		{"Linux media path", "/media/david/Pomona-4/Pomona/A05/2025-11-08/", "Pomona-4/Pomona/A05/2025-11-08"},
		{"macOS volumes path", "/Volumes/Drive/Audio/Recordings/", "Drive/Audio/Recordings"},
		{"Linux mnt path", "/mnt/storage/Audio/Files/", "storage/Audio/Files"},

		// Trailing slashes handled
		{"With trailing slash", "/media/david/USB/Audio/", "USB/Audio"},
		{"Without trailing slash", "/media/david/USB/Audio", "USB/Audio"},

		// Multiple levels
		{"Deep nested path", "/media/david/Pomona-4/Level1/Level2/Level3/", "Pomona-4/Level1/Level2/Level3"},

		// Edge cases
		{"File at mount root", "/media/david/", "."},
		{"Volumes with drive only", "/Volumes/Drive/", "Drive"},
		{"Volumes drive no trailing slash", "/Volumes/Drive", "Drive"},
		{"Root", "/", ""},
		{"Empty", "", "."},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := NormalizeFolderPath(tt.input)
			if result != tt.expected {
				t.Errorf("NormalizeFolderPath(%q) = %q, want %q", tt.input, result, tt.expected)
			}
		})
	}
}