package api

import "testing"

// R-182 — the backup run digest needs the allowlist half, and NOT the customerMessages half.
//
// A new event type is a pair of register entries, and each half fails differently. For this type the
// pair is unusual and that is the point:
//
//   - missing from `allowedEventTypes`            → POST /event returns 400 and the digest VANISHES,
//     which would rebuild the exact silence R-182 exists to end;
//   - PRESENT in `customerMessages`               → the customer would be e-mailed, in Hungarian, a
//     list of which apps' backups failed and why — operator detail they can take no action on. So
//     this type must be allowlisted and must NOT have a customer message.
//
// The customer-facing half of decision D-c is the FILL WARNING, which fires before this and is
// actionable (free space, delete files, add a drive). This is the operator's half.
//
// Operator-only routing itself is enforced by `notify.operatorOnlyEvents`, NOT by the absence of a
// customerMessages entry — that assumption shipped in v0.78.0 and was wrong, because
// FormatCustomerEmail falls back to the raw message. It is pinned in
// `internal/notify/backup_run_digest_test.go`, which demonstrates a customer with the type in their
// enabled list receiving nothing.
func TestBackupRunDigestIsAllowlisted(t *testing.T) {
	if !allowedEventTypes["backup_run_failures"] {
		t.Fatal("backup_run_failures must be in allowedEventTypes, or POST /event 400s and the " +
			"whole run digest is dropped at the door — the silence R-182 was filed against")
	}
}

// The per-app event is the RECORD and must not be removed while the digest is the notification.
// Deleting it would make the digest the only trace, and a digest that fails to send would then take
// the record with it — the coupling R-182's fix exists to break.
func TestPerAppCaptureEventStaysAllowlisted(t *testing.T) {
	if !allowedEventTypes["recovery_unit_capture_failed"] {
		t.Fatal("recovery_unit_capture_failed was removed from allowedEventTypes — it is the " +
			"durable per-failure RECORD, and the digest is only the notification; the operator " +
			"register and every historical query depend on it")
	}
}
