// Package integration contains the built-in integration data and admin
// surface contribution.
package integration

import (
	"strings"

	dataintegration "kra/internal/data/integration"
	"kra/internal/routecatalog"
	"kra/pkg/module"
)

func Definition() module.Definition {
	return module.Definition{
		Name:       "integration",
		Migrations: dataintegration.Migrations(),
		Surface: module.Surface{
			Menus: []module.Menu{{Name: "integrationConfig", Path: "integrationConfig", ParentName: "extensions", Component: "view/systemTools/integration/config.vue", Title: "通信集成", Icon: "connection", Sort: 8}},
			APIs:  integrationAPIs(),
		},
	}
}

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