package services

import "testing"

func TestAutomaticPilotRecipientScope(t *testing.T) {
	t.Setenv("CHATLOOP_AI_PILOT_RECIPIENTS", "")
	if !AutomaticRecipientAllowed("6281234567890") {
		t.Fatal("unset pilot changed normal routing")
	}
	t.Setenv("CHATLOOP_AI_PILOT_RECIPIENTS", "+62 812-3456-7001")
	for _, tc := range []struct {
		number string
		want   bool
	}{{"6281234567001", true}, {"+6281234567001", true}, {"6281234567002", false}, {"6281234567001@g.us", false}, {"", false}, {"628123456700", false}} {
		if got := AutomaticRecipientAllowed(tc.number); got != tc.want {
			t.Fatalf("%s: allowed=%t", tc.number, got)
		}
	}
	t.Setenv("CHATLOOP_AI_PILOT_RECIPIENTS", "invalid")
	if AutomaticRecipientAllowed("6281234567001") {
		t.Fatal("invalid pilot list allowed delivery")
	}
}
