package convertquery

import "testing"

func BenchmarkConvertEmptyQuery(b *testing.B) {
	// Setup for test
	// Create query conversion service
	service := NewService()

	query := []byte(`{
		"return": {
			"entities": [],
			"relations": []
		},
		"entities": [],
		"relations": [],
		"limit": 5000
	}`)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		service.ConvertQuery(&query)
	}
}

func BenchmarkConvertOneAttributeQuery(b *testing.B) {
	// Setup for test
	// Create query conversion service
	service := NewService()

	query := []byte(`{
		"return": {
			"entities": [
				0
			],
			"relations": []
		},
		"entities": [
			{
				"type": "airports",
				"constraints": [
					{
						"attribute": "state",
						"value": "HI",
						"dataType": "text",
						"matchType": "exact"
					}
				]
			}
		],
		"relations": [],
		"limit": 5000
	}`)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		service.ConvertQuery(&query)
	}
}

func BenchmarkConvertTwoRelationQuery(b *testing.B) {
	// Setup for test
	// Create query conversion service
	service := NewService()

	query := []byte(`{
		"return": {
			"entities": [
				0,
				1,
				2
			],
			"relations": [
				0,
				1
			]
		},
		"entities": [
			{
				"type": "airports",
				"constraints": [
					{
						"attribute": "city",
						"value": "New York",
						"dataType": "text",
						"matchType": "exact"
					}
				]
			},
			{
				"type": "airports",
				"constraints": [
					{
						"attribute": "city",
						"value": "San Francisco",
						"dataType": "text",
						"matchType": "exact"
					}
				]
			},
			{
				"type": "airports",
				"constraints": [
					{
						"attribute": "state",
						"value": "HI",
						"dataType": "text",
						"matchType": "exact"
					}
				]
			}
		],
		"relations": [
			{
				"type": "flights",
				"depth": {
					"min": 1,
					"max": 3
				},
				"entityFrom": 2,
				"entityTo": 1,
				"constraints": [
					{
						"attribute": "Day",
						"value": "15",
						"dataType": "number",
						"matchType": "EQ"
					}
				]
			},
			{
				"type": "flights",
				"depth": {
					"min": 1,
					"max": 1
				},
				"entityFrom": 0,
				"entityTo": -1,
				"constraints": []
			}
		],
		"limit": 5000
	}`)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		service.ConvertQuery(&query)
	}
}