package service

import (
	"testing"

	roomv1 "hyapp.local/api/proto/room/v1"
)

func TestRoomListSortScoreUsesCompressedWeightedInputs(t *testing.T) {
	score := roomListSortScore(7, 3, 2)
	if score != 2650000 {
		t.Fatalf("hot score should use 65/30/5 weighted compressed inputs, got %d", score)
	}
}

func TestRoomListSortScoreCapsPresenceInputs(t *testing.T) {
	capped := roomListSortScore(0, 50, 10)
	overCap := roomListSortScore(0, 999, 999)
	if capped != overCap {
		t.Fatalf("hot score should cap online and occupied seats, capped=%d over_cap=%d", capped, overCap)
	}
}

func TestRoomRocketNearCompletionUsesInclusiveTwentyPercentBoundary(t *testing.T) {
	tests := []struct {
		name    string
		rocket  *roomv1.RoomRocketState
		expects bool
	}{
		{name: "above boundary", rocket: &roomv1.RoomRocketState{Status: "charging", CurrentFuel: 79, FuelThreshold: 100}},
		{name: "exact boundary", rocket: &roomv1.RoomRocketState{Status: "charging", CurrentFuel: 80, FuelThreshold: 100}, expects: true},
		{name: "small threshold remains above twenty percent", rocket: &roomv1.RoomRocketState{Status: "charging", CurrentFuel: 3, FuelThreshold: 4}},
		{name: "already ignited", rocket: &roomv1.RoomRocketState{Status: "ignited", CurrentFuel: 100, FuelThreshold: 100}},
		{name: "invalid overflow", rocket: &roomv1.RoomRocketState{Status: "charging", CurrentFuel: 101, FuelThreshold: 100}},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			if got := roomRocketNearCompletion(test.rocket); got != test.expects {
				t.Fatalf("near-completion mismatch: got=%t want=%t rocket=%+v", got, test.expects, test.rocket)
			}
		})
	}
}
