package collector

import (
	"testing"

	"bee/audit/internal/schema"
)

func TestSetStorageHealthStatus(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name   string
		health storageHealthStatus
		want   string
	}{
		{
			name:   "smart overall failed",
			health: storageHealthStatus{hasOverall: true, overallPassed: false},
			want:   statusCritical,
		},
		{
			name:   "nvme critical warning",
			health: storageHealthStatus{criticalWarning: 1},
			want:   statusCritical,
		},
		{
			name:   "pending sectors",
			health: storageHealthStatus{pendingSectors: 1},
			want:   statusCritical,
		},
		{
			name:   "media errors warning",
			health: storageHealthStatus{mediaErrors: 2},
			want:   statusWarning,
		},
		{
			name:   "reallocated warning",
			health: storageHealthStatus{reallocatedSectors: 1},
			want:   statusWarning,
		},
		{
			name:   "life remaining low",
			health: storageHealthStatus{lifeRemainingPct: 8},
			want:   statusWarning,
		},
		{
			name:   "healthy",
			health: storageHealthStatus{},
			want:   statusOK,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			var disk schema.HardwareStorage
			setStorageHealthStatus(&disk, tt.health)
			if disk.Status == nil || *disk.Status != tt.want {
				t.Fatalf("status=%v want %q", disk.Status, tt.want)
			}
		})
	}
}
