package main

import (
	"testing"

	"hamlog/internal/qso"
)

// A self-spot announces OUR station, so it must carry the references we are
// activating (MY_POTA_REF…), never the QSO's award references — those belong to
// the station we worked, and spotting yourself with someone else's park number
// puts you somewhere you are not.
func TestSelfSpotComment(t *testing.T) {
	for name, c := range map[string]struct {
		q    qso.QSO
		want string
	}{
		"mode only": {
			q:    qso.QSO{Mode: "cw"},
			want: "CW",
		},
		"my park": {
			q:    qso.QSO{Mode: "SSB", MyPOTARef: "fr-11553"},
			want: "SSB POTA FR-11553",
		},
		"two references": {
			q:    qso.QSO{Mode: "CW", MyPOTARef: "FR-11553", MySOTARef: "F/AM-123"},
			want: "CW POTA FR-11553 SOTA F/AM-123",
		},
		// 30 characters is all a cluster keeps. The third reference is dropped
		// whole rather than cut in half.
		"too long drops the extra": {
			q: qso.QSO{
				Mode: "CW", MyPOTARef: "FR-11553", MySOTARef: "F/AM-123",
				MyWWFFRef: "FFF-0123",
			},
			want: "CW POTA FR-11553 SOTA F/AM-123",
		},
		// A QSO's own award references are the DX's, and must not leak in.
		"dx references are not ours": {
			q:    qso.QSO{Mode: "FT8", POTARef: "US-0001", AwardRefs: `{"POTA":"US-0001"}`},
			want: "FT8",
		},
	} {
		if got := selfSpotComment(c.q); got != c.want {
			t.Errorf("%s: got %q, want %q", name, got, c.want)
		}
		if got := selfSpotComment(c.q); len(got) > spotCommentMax {
			t.Errorf("%s: %d characters, over the %d a cluster keeps", name, len(got), spotCommentMax)
		}
	}
}
