package notify

import (
	"strings"
	"testing"
)

// E-2 — the Hungarian half of the backup_target_absent pair.
//
// Companion to api.TestBackupTargetEventTypesAreAllowlisted, which pins the allowlist half. They are
// deliberately two tests in two packages because the registers live in two packages, and the failure
// modes differ: an allowlist miss makes POST /event 400 (loud, the event is lost); a customerMessages
// miss delivers the event but falls back to the controller's raw operator English
// (templates.go FormatCustomerEmail: hunMessage == "" → message). The customer would receive
// "Backup target drive absent: ..." in English and nothing would look broken.
func TestBackupTargetCustomerMessagesArePresent(t *testing.T) {
	for _, et := range []string{"backup_target_absent", "backup_target_restored"} {
		msg, ok := customerMessages[et]
		if !ok || strings.TrimSpace(msg) == "" {
			t.Fatalf("customerMessages[%q] is missing — the event would be delivered to the customer "+
				"in the controller's operator English instead of Hungarian", et)
		}
	}
}

// The absent message must name the CONSEQUENCE, not just the fact. "A drive is missing" is a fact the
// customer can do nothing with; "the whole-system backup will not be made until you reconnect it" is
// the thing that makes them act. This pins the distinction the copy was written for — a future
// shortening to a bare "Meghajtó hiányzik." would pass the presence test above and lose the point.
func TestBackupTargetAbsentMessageNamesTheConsequence(t *testing.T) {
	msg := customerMessages["backup_target_absent"]
	if !strings.Contains(msg, "rendszermentés") {
		t.Errorf("backup_target_absent must name WHAT is at risk (the rendszermentés), got: %q", msg)
	}
	if !strings.Contains(strings.ToLower(msg), "nem készül") {
		t.Errorf("backup_target_absent must state the consequence (the backup will not be made), got: %q", msg)
	}
}
