package payment

import (
	"strings"
	"testing"

	"kra/internal/biz"
)

func TestPaymentDefinitionsProvideNonEmptyDefaults(t *testing.T) {
	definitions := biz.IntegrationDefinitions(biz.IntegrationKindPayment)
	if len(definitions) != len(biz.SupportedPaymentProviders) {
		t.Fatalf("payment definitions = %d, want %d", len(definitions), len(biz.SupportedPaymentProviders))
	}
	for _, definition := range definitions {
		if definition.Provider == "" || definition.Name == "" || len(definition.Fields) == 0 {
			t.Fatalf("incomplete payment definition: %+v", definition)
		}
		if len(definition.Defaults) == 0 {
			t.Fatalf("payment provider %s still has empty defaults", definition.Provider)
		}
	}
}

func TestPaymentValidationRejectsUnknownProvider(t *testing.T) {
	err := validatePaymentConfig("unknown-provider", map[string]any{})
	if err == nil || !strings.Contains(err.Error(), "不支持") {
		t.Fatalf("error = %v", err)
	}
}
