package task

import (
	"testing"

	"github.com/break/junhong_cmp_fiber/internal/model"
	"github.com/break/junhong_cmp_fiber/pkg/constants"
)

// TestShouldStopPolling 验证风险状态独立卡的轮询停止判断逻辑
func TestShouldStopPolling(t *testing.T) {
	cases := []struct {
		name          string
		isStandalone  bool
		gatewayExtend string
		want          bool
	}{
		{
			name:          "独立卡+风险停机 -> 停止轮询",
			isStandalone:  true,
			gatewayExtend: constants.GatewayCardExtendRiskStop,
			want:          true,
		},
		{
			name:          "独立卡+已销户 -> 停止轮询",
			isStandalone:  true,
			gatewayExtend: constants.GatewayCardExtendCancelled,
			want:          true,
		},
		{
			name:          "非独立卡+风险停机 -> 不停止轮询",
			isStandalone:  false,
			gatewayExtend: constants.GatewayCardExtendRiskStop,
			want:          false,
		},
		{
			name:          "独立卡+机卡分离停机 -> 不停止轮询",
			isStandalone:  true,
			gatewayExtend: constants.GatewayCardExtendMachineSeparated,
			want:          false,
		},
		{
			name:          "独立卡+空扩展 -> 不停止轮询",
			isStandalone:  true,
			gatewayExtend: "",
			want:          false,
		},
	}

	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			card := &model.IotCard{
				IsStandalone:  tc.isStandalone,
				GatewayExtend: tc.gatewayExtend,
			}
			got := shouldStopPollingForRisk(card, tc.gatewayExtend)
			if got != tc.want {
				t.Errorf("shouldStopPollingForRisk(standalone=%v, extend=%q) = %v, 期望 %v",
					tc.isStandalone, tc.gatewayExtend, got, tc.want)
			}
		})
	}
}
