package filterutil

import (
	"testing"
)

type FilterV1EqualsTestcase struct {
	name     string
	this     AllocationFilterV1
	that     AllocationFilterV1
	expected bool
}

func TestFilterV1_Equals(t *testing.T) {
	testCases := []FilterV1EqualsTestcase{
		{
			name: "both filters nil",
			this: AllocationFilterV1{
				Annotations:     nil,
				Containers:      nil,
				Controllers:     nil,
				ControllerKinds: nil,
				Clusters:        nil,
				Departments:     nil,
				Environments:    nil,
				Labels:          nil,
				Namespaces:      nil,
				Nodes:           nil,
				Owners:          nil,
				Pods:            nil,
				Products:        nil,
				Services:        nil,
				Teams:           nil,
			},
			that: AllocationFilterV1{
				Annotations:     nil,
				Containers:      nil,
				Controllers:     nil,
				ControllerKinds: nil,
				Clusters:        nil,
				Departments:     nil,
				Environments:    nil,
				Labels:          nil,
				Namespaces:      nil,
				Nodes:           nil,
				Owners:          nil,
				Pods:            nil,
				Products:        nil,
				Services:        nil,
				Teams:           nil,
			},
			expected: true,
		},
		{
			name: "both filters not nil and matching",
			this: AllocationFilterV1{
				Annotations:     []string{"a1", "b1"},
				Containers:      []string{"a1", "b1"},
				Controllers:     []string{"a1", "b1"},
				ControllerKinds: []string{"a1", "b1"},
				Clusters:        []string{"a1", "b1"},
				Departments:     []string{"a1", "b1"},
				Environments:    []string{"a1", "b1"},
				Labels:          []string{"a1", "b1"},
				Namespaces:      []string{"a1", "b1"},
				Nodes:           []string{"a1", "b1"},
				Owners:          []string{"a1", "b1"},
				Pods:            []string{"a1", "b1"},
				Products:        []string{"a1", "b1"},
				Services:        []string{"a1", "b1"},
				Teams:           []string{"a1", "b1"},
			},
			that: AllocationFilterV1{
				Annotations:     []string{"a1", "b1"},
				Containers:      []string{"a1", "b1"},
				Controllers:     []string{"a1", "b1"},
				ControllerKinds: []string{"a1", "b1"},
				Clusters:        []string{"a1", "b1"},
				Departments:     []string{"a1", "b1"},
				Environments:    []string{"a1", "b1"},
				Labels:          []string{"a1", "b1"},
				Namespaces:      []string{"a1", "b1"},
				Nodes:           []string{"a1", "b1"},
				Owners:          []string{"a1", "b1"},
				Pods:            []string{"a1", "b1"},
				Products:        []string{"a1", "b1"},
				Services:        []string{"a1", "b1"},
				Teams:           []string{"a1", "b1"},
			},
			expected: true,
		},
		{
			name: "both filters diff count",
			this: AllocationFilterV1{
				Annotations:     []string{"a1", "b1", "c1"},
				Containers:      []string{"a1", "b1"},
				Controllers:     []string{"a1", "b1"},
				ControllerKinds: []string{"a1", "b1"},
				Clusters:        []string{"a1", "b1"},
				Departments:     []string{"a1", "b1"},
				Environments:    []string{"a1", "b1"},
				Labels:          []string{"a1", "b1"},
				Namespaces:      []string{"a1", "b1"},
				Nodes:           []string{"a1", "b1"},
				Owners:          []string{"a1", "b1"},
				Pods:            []string{"a1", "b1"},
				Products:        []string{"a1", "b1"},
				Services:        []string{"a1", "b1"},
				Teams:           []string{"a1", "b1"},
			},
			that: AllocationFilterV1{
				Annotations:     []string{"a1", "b1"},
				Containers:      []string{"a1", "b1"},
				Controllers:     []string{"a1", "b1"},
				ControllerKinds: []string{"a1", "b1"},
				Clusters:        []string{"a1", "b1"},
				Departments:     []string{"a1", "b1"},
				Environments:    []string{"a1", "b1"},
				Labels:          []string{"a1", "b1"},
				Namespaces:      []string{"a1", "b1"},
				Nodes:           []string{"a1", "b1"},
				Owners:          []string{"a1", "b1"},
				Pods:            []string{"a1", "b1"},
				Products:        []string{"a1", "b1"},
				Services:        []string{"a1", "b1"},
				Teams:           []string{"a1", "b1"},
			},
			expected: false,
		},
		{
			name: "slight mismatch",
			this: AllocationFilterV1{
				Annotations:     []string{"x1", "b1"},
				Containers:      []string{"a1", "b1"},
				Controllers:     []string{"a1", "b1"},
				ControllerKinds: []string{"a1", "b1"},
				Clusters:        []string{"a1", "b1"},
				Departments:     []string{"a1", "b1"},
				Environments:    []string{"a1", "b1"},
				Labels:          []string{"a1", "b1"},
				Namespaces:      []string{"a1", "b1"},
				Nodes:           []string{"a1", "b1"},
				Owners:          []string{"a1", "b1"},
				Pods:            []string{"a1", "b1"},
				Products:        []string{"a1", "b1"},
				Services:        []string{"a1", "b1"},
				Teams:           []string{"a1", "b1"},
			},
			that: AllocationFilterV1{
				Annotations:     []string{"a1", "b1"},
				Containers:      []string{"a1", "b1"},
				Controllers:     []string{"a1", "b1"},
				ControllerKinds: []string{"a1", "b1"},
				Clusters:        []string{"a1", "b1"},
				Departments:     []string{"a1", "b1"},
				Environments:    []string{"a1", "b1"},
				Labels:          []string{"a1", "b1"},
				Namespaces:      []string{"a1", "b1"},
				Nodes:           []string{"a1", "b1"},
				Owners:          []string{"a1", "b1"},
				Pods:            []string{"a1", "b1"},
				Products:        []string{"a1", "b1"},
				Services:        []string{"a1", "b1"},
				Teams:           []string{"a1", "b1"},
			},
			expected: false,
		},
		{
			name: "one nil",
			this: AllocationFilterV1{
				Annotations:     []string{"x1", "b1"},
				Containers:      []string{"a1", "b1"},
				Controllers:     []string{"a1", "b1"},
				ControllerKinds: []string{"a1", "b1"},
				Clusters:        []string{"a1", "b1"},
				Departments:     []string{"a1", "b1"},
				Environments:    []string{"a1", "b1"},
				Labels:          []string{"a1", "b1"},
				Namespaces:      []string{"a1", "b1"},
				Nodes:           []string{"a1", "b1"},
				Owners:          []string{"a1", "b1"},
				Pods:            []string{"a1", "b1"},
				Products:        []string{"a1", "b1"},
				Services:        []string{"a1", "b1"},
				Teams:           []string{"a1", "b1"},
			},
			that: AllocationFilterV1{
				Annotations:     nil,
				Containers:      nil,
				Controllers:     nil,
				ControllerKinds: nil,
				Clusters:        nil,
				Departments:     nil,
				Environments:    nil,
				Labels:          nil,
				Namespaces:      nil,
				Nodes:           nil,
				Owners:          nil,
				Pods:            nil,
				Products:        nil,
				Services:        nil,
				Teams:           nil,
			},
			expected: false,
		},
	}

	for _, tc := range testCases {
		got := tc.this.Equals(tc.that)
		if got != tc.expected {
			t.Fatalf("expected %t, got: %t for test case: %s", tc.expected, got, tc.name)
		}
	}
}
