package discovery

import "testing"

func TestStableGatewayID(t *testing.T) {
	cases := []struct {
		name   string
		prefix string
		key    string
		want   string
	}{
		{name: "prefix and key", prefix: "crypto_rail_gateway", key: " TRON ", want: "crypto_rail_gateway_tron"},
		{name: "prefix trailing underscore", prefix: "payment_gateway_", key: " SETTLEMENT ", want: "payment_gateway_settlement"},
		{name: "missing key", prefix: "payment_gateway", key: " ", want: "payment_gateway_unknown"},
		{name: "missing prefix", prefix: " ", key: "TRON", want: "tron"},
	}

	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			got := StableGatewayID(tc.prefix, tc.key)
			if got != tc.want {
				t.Fatalf("unexpected stable gateway id: got=%q want=%q", got, tc.want)
			}
		})
	}
}

func TestStableCryptoRailGatewayID(t *testing.T) {
	if got, want := StableCryptoRailGatewayID(" TRON "), "crypto_rail_gateway_tron"; got != want {
		t.Fatalf("unexpected stable id: got=%q want=%q", got, want)
	}
	if got, want := StableCryptoRailGatewayID(""), "crypto_rail_gateway_unknown"; got != want {
		t.Fatalf("unexpected stable id for empty network: got=%q want=%q", got, want)
	}
}

func TestStablePaymentGatewayID(t *testing.T) {
	if got, want := StablePaymentGatewayID(" SETTLEMENT "), "payment_gateway_settlement"; got != want {
		t.Fatalf("unexpected stable id: got=%q want=%q", got, want)
	}
	if got, want := StablePaymentGatewayID(""), "payment_gateway_unknown"; got != want {
		t.Fatalf("unexpected stable id for empty rail: got=%q want=%q", got, want)
	}
}
