package gateway

import "testing"

func TestValidateCardPAN_AllowsFormattedInput(t *testing.T) {
	if err := validateCardPAN("4111 1111-1111 1111", "card_pan"); err != nil {
		t.Fatalf("expected formatted PAN to pass validation, got %v", err)
	}
}

func TestValidateCardPAN_RejectsInvalidChecksum(t *testing.T) {
	if err := validateCardPAN("4111111111111112", "card_pan"); err == nil {
		t.Fatal("expected invalid checksum to fail validation")
	}
}

func TestGeneratePANSeriesWithLuhn_ProducesValidUniquePANs(t *testing.T) {
	pans, err := generatePANSeriesWithLuhn("22000033", 6, 16)
	if err != nil {
		t.Fatalf("generatePANSeriesWithLuhn returned error: %v", err)
	}
	if len(pans) != 6 {
		t.Fatalf("unexpected PAN count: got=%d want=6", len(pans))
	}

	seen := map[string]struct{}{}
	for _, pan := range pans {
		if !isValidPANLuhn(pan) {
			t.Fatalf("generated PAN is not Luhn-valid: %q", pan)
		}
		if _, ok := seen[pan]; ok {
			t.Fatalf("duplicate PAN generated: %q", pan)
		}
		seen[pan] = struct{}{}
	}
}
