package adif

import (
	"strings"
	"testing"
)

// An import must never INVENT a routing method. The two "via" fields carry what
// the file carries, and nothing at all when it carries nothing.
//
// This is worth pinning because the opposite is easy to reach for: a card that
// was confirmed electronically is the common case, and defaulting to E would
// quietly rewrite the operator's own record of how their cards actually
// travelled. Where an E does show up after an import, it came from the source
// file — Log4OM writes QSL_SENT_VIA:1>E on every record whether or not a card
// was ever sent, which is pinned by TestQSLSentViaDoesNotBecomeManager.
func TestImportInventsNoQSLRouting(t *testing.T) {
	for name, rec := range map[string]string{
		"absent":     "<CALL:5>OE6CLD<QSO_DATE:8>20260606<TIME_ON:4>1200<BAND:3>20m<MODE:2>CW<EOR>\n",
		"empty":      "<CALL:5>OE6CLD<QSO_DATE:8>20260606<TIME_ON:4>1200<BAND:3>20m<MODE:2>CW<QSL_SENT_VIA:0><QSL_RCVD_VIA:0><EOR>\n",
		"whitespace": "<CALL:5>OE6CLD<QSO_DATE:8>20260606<TIME_ON:4>1200<BAND:3>20m<MODE:2>CW<QSL_SENT_VIA:1> <QSL_RCVD_VIA:1> <EOR>\n",
		// Not in the enumeration: dropped rather than passed through, or the
		// export would write a value no other logger can read.
		"unknown": "<CALL:5>OE6CLD<QSO_DATE:8>20260606<TIME_ON:4>1200<BAND:3>20m<MODE:2>CW<QSL_SENT_VIA:3>ZZZ<EOR>\n",
	} {
		var got Record
		if err := Parse(strings.NewReader("<EOH>\n"+rec), func(r Record) error { got = r; return nil }); err != nil {
			t.Fatalf("%s: parse: %v", name, err)
		}
		q, ok := recordToQSO(got)
		if !ok {
			t.Fatalf("%s: recordToQSO returned !ok", name)
		}
		if q.QSLSentVia != "" {
			t.Errorf("%s: QSL_SENT_VIA = %q, want empty — the import made up a routing method", name, q.QSLSentVia)
		}
		if q.QSLRcvdVia != "" {
			t.Errorf("%s: QSL_RCVD_VIA = %q, want empty — the import made up a routing method", name, q.QSLRcvdVia)
		}
	}
}
