package bandopen

import (
	"testing"
	"time"
)

// A 2 m "opening" was announced at 9650 km towards Japan on stations that were
// plainly working EME. The moon is not an opening: an operator pointing an
// antenna at that bearing finds nothing.
func TestEMEIsNotAnOpeningOnTwoMetres(t *testing.T) {
	d := New(DefaultConfig())
	base := time.Date(2026, 8, 12, 6, 0, 0, 0, time.UTC)
	for i, call := range []string{"7M4RRM", "JA7RPC", "JF1AWC", "JK1TPA", "JH1JCQ"} {
		if op := d.Add(Spot{
			Call: call, Band: "2m", DistKm: 9650, Bearing: 40 + i*3,
			At: base.Add(time.Duration(i) * time.Minute),
		}, 47.0); op != nil {
			t.Fatalf("a 9650 km 2 m path was announced as an opening: %+v", op)
		}
	}
}

// But a real 2 m opening — an Es chain at a plausible distance — must survive.
func TestLongButPlausibleTwoMetresStillCounts(t *testing.T) {
	d := New(DefaultConfig())
	base := time.Date(2026, 6, 20, 18, 0, 0, 0, time.UTC)
	var got *Opening
	for i, call := range []string{"EA1AA", "CT1BB", "EA7CC", "CT7DD"} {
		if op := d.Add(Spot{
			Call: call, Band: "2m", DistKm: 2000 + i*30, Bearing: 200 + i*4,
			At: base.Add(time.Duration(i) * time.Minute),
		}, 47.0); op != nil {
			got = op
		}
	}
	if got == nil {
		t.Fatal("a 2000 km 2 m burst in one sector was not reported")
	}
}

// Six metres keeps no ceiling: multi-hop Es genuinely goes that far, which is
// why the flat limit was removed in the first place.
func TestSixMetresHasNoCeiling(t *testing.T) {
	if MaxKmFor("6m") != 0 || MaxKmFor("10m") != 0 {
		t.Error("6 m and 10 m must have no distance ceiling")
	}
	if MaxKmFor("2m") == 0 {
		t.Error("2 m must have one")
	}
}
