// Package app is the composition root for the running administration service.
// It knows which business modules are enabled and wires their contributions
// into the shared platform. Individual modules do not import this package.
package app

import (
	systemrouter "kra/internal/server/router"
	systemworker "kra/internal/worker"
	"kra/pkg/module"
	platformtask "kra/pkg/task"
)

// Catalog lists the business modules enabled in this binary. Adding an order
// module means adding one Definition here; system initialization and runtime
// code consume the catalog without knowing that module's implementation.
func Catalog() module.Catalog {
	return module.Catalog{Definitions: []module.Definition{Definition()}}
}

// TaskRegistry builds the process-wide registry from dependency-free module
// contributions. Dependency-bearing methods are added by their module runtime
// constructors after the usecases have been created.
func TaskRegistry(catalog module.Catalog) *platformtask.Registry {
	registry := platformtask.NewRegistry()
	registry.RegisterAll(catalog.TaskMethods())
	return registry
}

// Runtime composes HTTP route contributors from the enabled modules.
func Runtime(systemRoutes *systemrouter.Routes, systemTasks *systemworker.TaskMethods, registry *platformtask.Registry) *module.Runtime {
	platformtask.Apply(registry, systemTasks)
	return module.NewRuntime(systemRoutes)
}
