package core

import (
	"errors"
	"testing"
)

func TestHealthRegistry(t *testing.T) {
	tests := []struct {
		name         string
		registerFail bool
		critical     bool
		wantHealthy  bool
	}{
		{name: "no extra checks beyond self is healthy", wantHealthy: true},
		{name: "a failing optional check does not affect the aggregate", registerFail: true, critical: false, wantHealthy: true},
		{name: "a failing critical check makes the aggregate unhealthy", registerFail: true, critical: true, wantHealthy: false},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			registry := NewRegistry()
			if tt.registerFail {
				registry.Register(Check{
					Name:     "extra",
					Critical: tt.critical,
					Run:      func() error { return errors.New("boom") },
				})
			}

			healthy, results := registry.Report()
			if healthy != tt.wantHealthy {
				t.Errorf("Report() healthy = %v, want %v (results: %+v)", healthy, tt.wantHealthy, results)
			}
		})
	}
}
