package config

import "testing"

func TestIsInList(t *testing.T) {
	cases := []struct {
		name     string
		config   O11yRegionalServerTestConfig
		tenant   string
		project  string
		expected bool
	}{
		{
			name: "tenant in list",
			config: O11yRegionalServerTestConfig{
				Enable:       true,
				Tenants:      []string{"tenant1"},
				TestEndpoint: "http://test-endpoint",
			},
			tenant:   "tenant1",
			project:  "project1",
			expected: true,
		},
		{
			name: "project in list",
			config: O11yRegionalServerTestConfig{
				Enable:       true,
				Projects:     []string{"project1"},
				TestEndpoint: "http://test-endpoint",
			},
			tenant:   "tenant1",
			project:  "project1",
			expected: true,
		},
		{
			name: "tenant and project in list",
			config: O11yRegionalServerTestConfig{
				Enable:       true,
				Tenants:      []string{"tenant1"},
				Projects:     []string{"project1"},
				TestEndpoint: "http://test-endpoint",
			},
			tenant:   "tenant1",
			project:  "project1",
			expected: true,
		},
		{
			name: "tenant and project not in list",
			config: O11yRegionalServerTestConfig{
				Enable:   true,
				Tenants:  []string{"tenant1"},
				Projects: []string{"project1"},
			},
			tenant:   "tenant2",
			project:  "project2",
			expected: false,
		},
		{
			name: "dev endpoint disabled",
			config: O11yRegionalServerTestConfig{
				Enable: false,
			},
			tenant:   "tenant1",
			project:  "project1",
			expected: false,
		},
		{
			name: "empty endpoint",
			config: O11yRegionalServerTestConfig{
				Enable:   true,
				Tenants:  []string{"tenant1"},
				Projects: []string{"project1"},
			},
			tenant:   "tenant1",
			project:  "project1",
			expected: false,
		},
	}

	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			if got := tc.config.IsInList(tc.tenant, tc.project); got != tc.expected {
				t.Errorf("IsInList() = %v, want %v", got, tc.expected)
			}
		})
	}
}
