package application

import (
	"context"
	"log/slog"

	"github.com/costap/quarkshologridledger/tongo-core/internal/domain/port"
)

// Engine is the top-level orchestrator for the Tongo Core simulation.
// It coordinates the scheduler, simulator, event generator, probability engine, and cache.
type Engine struct {
	scheduler   port.SchedulerService
	matchmaker  port.MatchmakerService
	simulator   port.SimulatorService
	events      port.EventGeneratorService
	probability port.ProbabilityService
	markets     port.MarketService
	cache       port.CachePort
	taxonomy    port.TaxonomyPort
	logger      *slog.Logger
}

// EngineDeps holds all dependencies for engine construction.
type EngineDeps struct {
	Scheduler   port.SchedulerService
	Matchmaker  port.MatchmakerService
	Simulator   port.SimulatorService
	Events      port.EventGeneratorService
	Probability port.ProbabilityService
	Markets     port.MarketService
	Cache       port.CachePort
	Taxonomy    port.TaxonomyPort
	Logger      *slog.Logger
}

// NewEngine creates a new Engine with all service dependencies.
func NewEngine(deps EngineDeps) *Engine {
	return &Engine{
		scheduler:   deps.Scheduler,
		matchmaker:  deps.Matchmaker,
		simulator:   deps.Simulator,
		events:      deps.Events,
		probability: deps.Probability,
		markets:     deps.Markets,
		cache:       deps.Cache,
		taxonomy:    deps.Taxonomy,
		logger:      deps.Logger,
	}
}

// Run starts the main simulation loop. It blocks until ctx is cancelled.
func (e *Engine) Run(ctx context.Context) error {
	e.logger.Info("Starting Tongo Core simulation loop")
	// TODO: implement actual tick logic
	<-ctx.Done()
	return nil
}

// Shutdown gracefully stops the engine.
func (e *Engine) Shutdown() error {
	e.logger.Info("Stopping Tongo Core simulation engine")
	return nil
}

