package collector

import (
	"testing"

	"bee/audit/internal/schema"
)

func TestEnrichPSUsWithTelemetry(t *testing.T) {
	slot0 := "0"
	slot1 := "1"
	psus := []schema.HardwarePowerSupply{
		{Slot: &slot0},
		{Slot: &slot1},
	}

	doc := sensorsDoc{
		"psu-hwmon-0": {
			"PSU1 Temp":           map[string]any{"temp1_input": 39.5},
			"PSU2 Temp":           map[string]any{"temp2_input": 41.0},
			"PSU1 Health":         map[string]any{"health1_input": 98.0},
			"PSU2 Remaining Life": map[string]any{"life2_input": 95.0},
		},
	}

	got := enrichPSUsWithTelemetry(psus, doc)
	if got[0].TemperatureC == nil || *got[0].TemperatureC != 39.5 {
		t.Fatalf("psu0 temperature mismatch: %#v", got[0].TemperatureC)
	}
	if got[1].TemperatureC == nil || *got[1].TemperatureC != 41.0 {
		t.Fatalf("psu1 temperature mismatch: %#v", got[1].TemperatureC)
	}
	if got[0].LifeRemainingPct == nil || *got[0].LifeRemainingPct != 98.0 {
		t.Fatalf("psu0 life remaining mismatch: %#v", got[0].LifeRemainingPct)
	}
	if got[0].LifeUsedPct == nil || *got[0].LifeUsedPct != 2.0 {
		t.Fatalf("psu0 life used mismatch: %#v", got[0].LifeUsedPct)
	}
	if got[1].LifeRemainingPct == nil || *got[1].LifeRemainingPct != 95.0 {
		t.Fatalf("psu1 life remaining mismatch: %#v", got[1].LifeRemainingPct)
	}
}
