package notify

import (
	"strings"
	"testing"
)

// NotifyDiskHealthDegraded emits the right event type + severity + a message carrying the required
// "Lemez állapot romlás: <label>" phrase and the triggering attribute(s). Uses the pushFn seam.
func TestNotifyDiskHealthDegraded(t *testing.T) {
	n := &Notifier{}
	var gotType, gotSev, gotMsg string
	var gotDetails interface{}
	n.pushFn = func(eventType, severity, message string, details interface{}) {
		gotType, gotSev, gotMsg, gotDetails = eventType, severity, message, details
	}

	// Warn (Figyelmeztetés): severity warn, attributes named.
	n.NotifyDiskHealthDegraded("sdb (lassú)", []string{"függőben lévő szektorok"}, false)
	if gotType != "disk_health_degraded" {
		t.Errorf("event type = %q, want disk_health_degraded", gotType)
	}
	if gotSev != "warn" {
		t.Errorf("severity = %q, want warn", gotSev)
	}
	if !strings.Contains(gotMsg, "Lemez állapot romlás: sdb (lassú)") {
		t.Errorf("message missing the required subject phrase: %q", gotMsg)
	}
	if !strings.Contains(gotMsg, "függőben lévő szektorok") {
		t.Errorf("message does not name the triggering attribute: %q", gotMsg)
	}
	if d, ok := gotDetails.(DiskHealthDetails); !ok || d.Disk != "sdb (lassú)" || d.Critical {
		t.Errorf("details = %+v, want DiskHealthDetails{Disk:sdb (lassú), Critical:false}", gotDetails)
	}

	// Critical (Hiba/FAILING): severity critical.
	n.NotifyDiskHealthDegraded("sdc", nil, true)
	if gotSev != "critical" {
		t.Errorf("critical severity = %q, want critical", gotSev)
	}
	if !strings.Contains(gotMsg, "SMART önellenőrzése hibát jelez") {
		t.Errorf("critical message wrong: %q", gotMsg)
	}
}
