// Package main provides the application entry point for the Go Platform.
package main

import (
	"context"
	"fmt"
	"os"

	"git.dcentral.systems/toolz/goplt/internal/di"
	"git.dcentral.systems/toolz/goplt/internal/health"
	"git.dcentral.systems/toolz/goplt/internal/metrics"
	"git.dcentral.systems/toolz/goplt/pkg/config"
	"git.dcentral.systems/toolz/goplt/pkg/logger"
	"go.uber.org/fx"
)

func main() {
	// Create DI container with lifecycle hooks
	// This is a minimal entry point for testing core kernel infrastructure
	// Services will have their own entry points (cmd/{service}/main.go)
	container := di.NewContainer(
		// Invoke lifecycle hooks
		fx.Invoke(di.RegisterLifecycleHooks),
		// Verify core kernel services are available
		fx.Invoke(func(
			_ config.ConfigProvider,
			_ logger.Logger,
			_ *health.Registry,
			_ *metrics.Metrics,
		) {
			// Core kernel services are available
		}),
	)

	// Create root context
	ctx := context.Background()

	// Start the application
	if err := container.Start(ctx); err != nil {
		log := logger.GetGlobalLogger()
		if log != nil {
			log.Error("Failed to start application",
				logger.Error(err),
			)
		} else {
			fmt.Fprintf(os.Stderr, "Failed to start application: %v\n", err)
		}
		os.Exit(1)
	}
}
