package wang.yaojia.webterm.wiring

import wang.yaojia.webterm.hostregistry.HostStore
import javax.inject.Inject

/** Where the app should land on a cold launch (plan §1 P1 continue-last-session; A29). */
public enum class ColdStartRoute {
    /** No paired host yet → the pairing flow (A19). */
    PAIRING,

    /** At least one paired host → the session chooser / dashboard (A20). */
    SESSIONS,
}

/**
 * The cold-start routing seam A29 consumes (plan §5 A15/A29): decide the FIRST destination from
 * persisted state alone — no host → pairing, else sessions. Kept behind an interface so A29's nav
 * wiring and its tests depend on the decision, not on the store.
 */
public interface ColdStartPolicy {
    /** The initial route, derived from whether any host is paired. Suspends for the [HostStore] read. */
    public suspend fun initialRoute(): ColdStartRoute
}

/**
 * Default [ColdStartPolicy]: route on host presence via [HostStore]. The "continue-last-session"
 * re-entry banner (A29) is layered ON TOP of a [ColdStartRoute.SESSIONS] landing from
 * `LastSessionStore` — this policy only chooses pairing-vs-sessions, keeping the decision minimal.
 */
public class DefaultColdStartPolicy @Inject constructor(
    private val hostStore: HostStore,
) : ColdStartPolicy {
    override suspend fun initialRoute(): ColdStartRoute =
        if (hostStore.loadAll().isEmpty()) ColdStartRoute.PAIRING else ColdStartRoute.SESSIONS
}
