package cat

import "testing"

// A genuine split is two same-band slices in the SAME split class (both PHONE or
// both CW). Two same-band slices in different modes (SSB + FT8), or in a data
// mode (FT8/FT4/RTTY = DIGU/DIGL), must NOT read as split.
func TestOperatingSplitMode(t *testing.T) {
	mk := func(hz int64, mode string, active, tx bool) *flexSlice {
		return &flexSlice{freqHz: hz, mode: mode, active: active, tx: tx, inUse: true}
	}
	cases := []struct {
		name      string
		slices    map[int]*flexSlice
		wantSplit bool
	}{
		{"phone split (both USB)", map[int]*flexSlice{
			0: mk(14_100_000, "USB", true, false),
			1: mk(14_200_000, "USB", false, true),
		}, true},
		{"CW split (both CW)", map[int]*flexSlice{
			0: mk(7_010_000, "CW", true, false),
			1: mk(7_025_000, "CW", false, true),
		}, true},
		{"SSB + FT8 same band → not split", map[int]*flexSlice{
			0: mk(14_100_000, "USB", true, false),
			1: mk(14_074_000, "DIGU", false, true),
		}, false},
		{"both FT8 (DIGU) same band → not split", map[int]*flexSlice{
			0: mk(14_074_000, "DIGU", true, false),
			1: mk(14_080_000, "DIGU", false, true),
		}, false},
		{"different bands → not split", map[int]*flexSlice{
			0: mk(14_100_000, "USB", true, false),
			1: mk(7_100_000, "LSB", false, true),
		}, false},
		{"simplex (single slice) → not split", map[int]*flexSlice{
			0: mk(14_100_000, "USB", true, true),
		}, false},
	}
	for _, c := range cases {
		f := &Flex{slices: c.slices}
		_, rx, tx := f.operatingLocked()
		gotSplit := rx != nil && tx != nil
		if gotSplit != c.wantSplit {
			t.Errorf("%s: split=%v, want %v", c.name, gotSplit, c.wantSplit)
		}
	}
}
