package payment

import (
	"kra/pkg/database/migration"
	platformmodule "kra/pkg/module"

	"gorm.io/gorm"
)

func Migrations() []migration.Step {
	return []migration.Step{
		{ID: "202608200003_payment_schema", Migrate: func(db *gorm.DB) error {
			return migration.CreateMissingTables(db, &paymentOrderPO{})
		}},
		{ID: "202608200004_payment_defaults", Migrate: ensurePaymentIntegrationConfigs},
	}
}

// AdminSurface describes the payment-owned entries shown in the system
// administration UI. The system module persists these records because it owns
// the menu/API/policy tables.
func AdminSurface() platformmodule.Surface {
	return platformmodule.Surface{
		Menus: []platformmodule.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: []platformmodule.API{
			{Path: "/integration/configs/:kind", Method: "GET", Group: "集成配置", Description: "按类型获取集成配置"},
			{Path: "/integration/configs/:kind/:provider", Method: "GET", Group: "集成配置", Description: "获取指定集成配置"},
			{Path: "/integration/configs/:kind/:provider", Method: "PUT", Group: "集成配置", Description: "保存集成配置"},
			{Path: "/integration/configs/:kind/:provider", Method: "DELETE", Group: "集成配置", Description: "删除集成配置"},
			{Path: "/payment/orders", Method: "GET", Group: "支付", Description: "分页查询支付订单"},
			{Path: "/payment/order", Method: "POST", Group: "支付", Description: "查询支付订单"},
		},
	}
}
