// Package payment contains the payment module contribution to the application
// catalog.
package payment

import (
	"strings"

	datapayment "kra/internal/data/payment"
	"kra/internal/routecatalog"
	"kra/pkg/module"
)

// Definition declares the payment-owned schema and administration surface.
func Definition() module.Definition {
	return module.Definition{
		Name:       "payment",
		Migrations: datapayment.Migrations(),
		Surface: module.Surface{
			Menus: []module.Menu{
				{Name: "paymentOrders", Path: "paymentOrders", ParentName: "extensions", Component: "view/systemTools/payment/orders.vue", Title: "支付订单", Icon: "wallet", Sort: 6},
				{Name: "paymentConfig", Path: "paymentConfig", ParentName: "extensions", Component: "view/systemTools/payment/config.vue", Title: "支付配置", Icon: "credit-card", Sort: 7},
			},
			APIs: paymentAPIs(),
		},
	}
}

func paymentAPIs() []module.API {
	items := make([]module.API, 0, 10)
	for _, descriptor := range routecatalog.Descriptors() {
		if descriptor.Public || !strings.HasPrefix(descriptor.Path, "/payment") || descriptor.Description == "" {
			continue
		}
		items = append(items, module.API{Path: descriptor.Path, Method: descriptor.Method, Group: descriptor.Group, Description: descriptor.Description})
	}
	return items
}
