package consts

import (
	"testing"
)

func TestIsUIRequest(t *testing.T) {
	testCases := []struct {
		name     string
		path     string
		expected bool
	}{
		{
			name:     "UI request",
			path:     "/serverless/api/v1beta1/regions",
			expected: true,
		},
		{
			name:     "Non-UI request",
			path:     "/serverless/v1beta1/clusters",
			expected: false,
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			actual := IsUIRequest(tc.path)
			if actual != tc.expected {
				t.Errorf("IsUIRequest() = %v, want %v", actual, tc.expected)
			}
		})
	}
}

func TestRelativePath(t *testing.T) {
	testCases := []struct {
		name     string
		path     string
		expected string
	}{
		{
			name:     "UI request",
			path:     "/serverless/api/v1beta1/regions",
			expected: "/serverless/regions",
		},
		{
			name:     "Non-UI request",
			path:     "/dedicated/v1beta1/regions",
			expected: "/dedicated/regions",
		},
		{
			name:     "bff api request",
			path:     "/api/v2023/clusterManagement/v1beta1/clusters",
			expected: "/clusterManagement/clusters",
		},
		{
			name:     "dedicated ui request",
			path:     "/api/v2023/dedicated/v1beta1/clusters",
			expected: "/dedicated/clusters",
		},
		{
			name:     "nginx ui request",
			path:     "/api/v2025/cloud/v1beta2/tidbs/10411292523848492340/publicConnectionSetting",
			expected: "/tidbs/10411292523848492340/publicConnectionSetting",
		},
		{
			name:     "v1beta2 tidb private endpoint connection",
			path:     "/api/v2025/cloud/v1beta2/tidbs/10168629357304915512/privateEndpointConnections",
			expected: "/tidbs/10168629357304915512/privateEndpointConnections",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			actual := RelativePath(tc.path)
			if actual != tc.expected {
				t.Errorf("RelativePath() = %v, want %v", actual, tc.expected)
			}
		})
	}
}
