package wang.yaojia.webterm.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import wang.yaojia.webterm.hostregistry.HostStore
import wang.yaojia.webterm.wiring.ColdStartPolicy
import wang.yaojia.webterm.wiring.DefaultColdStartPolicy
import javax.inject.Singleton

/**
 * Session-wiring boundary (A15): the cold-start route seam.
 *
 * The per-host / per-session builders (`ApiClientFactory`, `SessionEngineFactory`) and the composition
 * root (`AppEnvironment`) are constructor-injected (`@Inject`), so Hilt provides them without an entry
 * here — this module only wires the [ColdStartPolicy] interface binding.
 *
 * NOTE (FIX 1): there is deliberately NO `EventBus` provider. The engine→UI fan-out is PER-SESSION —
 * a fresh `EventBus` is minted inside `RetainedSessionHolder.bind()` alongside each engine's confined
 * scope, so two sessions never share one bus (an app-wide singleton would cross-talk `Output`/`Gate`
 * between sessions since `SessionEvent` carries no session id).
 */
@Module
@InstallIn(SingletonComponent::class)
public object SessionModule {

    /** Bind the cold-start seam A29 consumes to the host-presence policy. */
    @Provides
    @Singleton
    public fun provideColdStartPolicy(hostStore: HostStore): ColdStartPolicy =
        DefaultColdStartPolicy(hostStore)
}
