package qso

import "testing"

// Mode, submode and RST are repair fields: an import that mapped every contact
// to SSB, or an ADIF that carried no MODE, is fixed in one pass instead of one
// row at a time. They were excluded as "per-QSO", which confused describing a
// QSO with repairing a batch of them.
func TestModeAndRSTAreBulkEditable(t *testing.T) {
	for _, col := range []string{"mode", "submode", "rst_sent", "rst_rcvd"} {
		if !bulkEditableCols[col] {
			t.Errorf("%s should be bulk-editable", col)
		}
	}
}

// Band must NOT be bulk-editable on its own: it travels with the frequency
// through BulkSetFrequency. A band contradicting its own frequency is invalid
// ADIF, and every export would carry the contradiction out into the world.
func TestBandIsNotBulkEditableAlone(t *testing.T) {
	for _, col := range []string{"band", "freq_hz", "callsign", "qso_date"} {
		if bulkEditableCols[col] {
			t.Errorf("%s must not be bulk-editable on its own", col)
		}
	}
}

// A log uploaded to HAMLOG.online BY HAND has to be markable afterwards, or
// OpsLog offers to send every one of those contacts again. Both directions live
// in extras — the ADIF names a field for hamlog.EU and none for hamlog.ONLINE —
// so they must be reachable through the extras path, not the column one.
func TestHamlogFieldsAreBulkEditable(t *testing.T) {
	for field, want := range map[string]string{
		"hamlog_sent":      "APP_OPSLOG_HAMLOG_SENT",
		"hamlog_sent_date": "APP_OPSLOG_HAMLOG_SENT_DATE",
		// Their field name — see award.HamlogQSLKey. Editing it by hand and
		// importing their ADIF must land in the SAME place.
		"hamlog_rcvd":      "APP_HAMLOG_QSO_CFM",
		"hamlog_rcvd_date": "APP_OPSLOG_HAMLOG_QSL_DATE",
	} {
		if got := BulkExtraKey(field); got != want {
			t.Errorf("BulkExtraKey(%q) = %q, want %q", field, got, want)
		}
	}
	// And they are NOT columns: a mapping that also claimed a column would write
	// to a table that has none.
	for _, col := range []string{"hamlog_sent", "hamlog_rcvd", "APP_OPSLOG_HAMLOG_SENT"} {
		if BulkEditable(col) {
			t.Errorf("%q is offered as a bulk-editable COLUMN", col)
		}
	}
}
