package engine

import (
	"github.com/stretchr/testify/require"
	"testing"
)

var testTransitionQueryInfo = map[string]TransitionQueryInfo{
	"1828a670-5957-4bc5-9974-47da228f75e2": {
		QueryID:    "1828a670-5957-4bc5-9974-47da228f75e2",
		QueryName:  "Query3",
		Transition: 3,
	},
	"cf34805e-3872-4c08-bf92-6ff7bb0cfadb": {
		QueryID:    "cf34805e-3872-4c08-bf92-6ff7bb0cfadb",
		QueryName:  "Query5",
		Transition: 5,
	},
	"c3162390-7f18-4f31-8c73-da1d86c8a11e": {
		QueryID:    "c3162390-7f18-4f31-8c73-da1d86c8a11e",
		QueryName:  "Query1",
		Transition: 1,
	},
	"788996a7-4359-4568-9a91-1ad0c4112818": {
		QueryID:    "788996a7-4359-4568-9a91-1ad0c4112818",
		QueryName:  "Query2",
		Transition: 2,
	},
	"77f5d46e-7244-4606-80c6-18478627aa9e": {
		QueryID:    "77f5d46e-7244-4606-80c6-18478627aa9e",
		QueryName:  "Query4",
		Transition: 4,
	},
}

func TestCheckQueryTransitionType(t *testing.T) {

	tests := []struct {
		name     string
		changeID string
		expected VulnerabilityBuilderTransition
	}{
		{
			name:     "Query with transition type 3 - AddedSearchValue ",
			changeID: "1828a670-5957-4bc5-9974-47da228f75e2",
			expected: AddedSearchValue,
		},
		{
			name:     "Query with transition type 5 - AddedSearchValueAndAddedSearchLine",
			changeID: "cf34805e-3872-4c08-bf92-6ff7bb0cfadb",
			expected: AddedSearchValueAndAddedSearchLine,
		},
		{
			name:     "Query with transition type 1 - NonGracefullyTransition",
			changeID: "c3162390-7f18-4f31-8c73-da1d86c8a11e",
			expected: NonGracefullyTransition,
		},
		{
			name:     "Query with transition type 2 - TransitionWithoutChanges",
			changeID: "788996a7-4359-4568-9a91-1ad0c4112818",
			expected: TransitionWithoutChanges,
		},
		{
			name:     "Query with transition type 4 - AddedSearchLine",
			changeID: "77f5d46e-7244-4606-80c6-18478627aa9e",
			expected: AddedSearchLine,
		},
		{
			name:     "Query with transition type 0 - YetToBeChecked",
			changeID: "non-existing-query-id",
			expected: YetToBeChecked,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := checkQueryTransitionType(testTransitionQueryInfo, tt.changeID)
			require.Equal(t, tt.expected, result)
		})
	}

}
