package powergenius

import "testing"

// The amplifier's status frame has no "operate=" field: its live state is in
// "state", and that is what says whether the amp is in line. Reading only
// operate= meant the flag was never read at all — OpsLog opened claiming
// STANDBY on an amp that was operating, and the first press of the button
// commanded the state it was already in.
func TestOperateIsReadFromTheStateField(t *testing.T) {
	cases := []struct {
		state   string
		operate bool
		known   bool
	}{
		{"STANDBY", false, true},
		{"OFF", false, true},
		{"OPERATE", true, true},
		// IDLE is the one that matters: the amp is IN LINE, simply not keyed.
		// Reading it as standby is how the wrong state got on screen.
		{"IDLE", true, true},
		{"TRANSMIT_A", true, true},
		{"idle", true, true}, // case is the firmware's business, not ours
		// A state nobody has seen leaves the flag alone rather than guessing:
		// claiming STANDBY on an amp that is in line is the error that matters.
		{"WARMING_UP", false, false},
		{"", false, false},
	}
	for _, c := range cases {
		op, known := operateFromState(c.state)
		if known != c.known {
			t.Errorf("state %q: known = %v, want %v", c.state, known, c.known)
			continue
		}
		if known && op != c.operate {
			t.Errorf("state %q: operate = %v, want %v", c.state, op, c.operate)
		}
	}
}
