package sortkey

import (
	"reflect"
	"testing"
)

func TestActivePositiveSortClauses(t *testing.T) {
	t.Run("ascending without alias", func(t *testing.T) {
		got := ActivePositiveSortClauses("", "is_active", "sortkey", "designation", false)
		want := []string{
			"is_active DESC",
			"CASE WHEN is_active = 1 AND sortkey IS NOT NULL AND sortkey >= 0 THEN 0 ELSE 1 END ASC",
			"CASE WHEN is_active = 1 AND sortkey IS NOT NULL AND sortkey >= 0 THEN sortkey END ASC",
			"designation ASC",
		}
		if !reflect.DeepEqual(got, want) {
			t.Fatalf("unexpected clauses: got=%v want=%v", got, want)
		}
	})

	t.Run("descending with alias", func(t *testing.T) {
		got := ActivePositiveSortClauses("helicopters", "is_active", "sortkey", "designation", true)
		want := []string{
			"helicopters.is_active DESC",
			"CASE WHEN helicopters.is_active = 1 AND helicopters.sortkey IS NOT NULL AND helicopters.sortkey >= 0 THEN 0 ELSE 1 END ASC",
			"CASE WHEN helicopters.is_active = 1 AND helicopters.sortkey IS NOT NULL AND helicopters.sortkey >= 0 THEN helicopters.sortkey END DESC",
			"helicopters.designation ASC",
		}
		if !reflect.DeepEqual(got, want) {
			t.Fatalf("unexpected clauses: got=%v want=%v", got, want)
		}
	})
}
