package wang.yaojia.webterm.hostregistry

/**
 * Frozen contract (plan §3 / A29). Persists the last server-adopted sessionId PER
 * HOST — NON-SECRET UI state only (anything sensitive belongs in the device-cert
 * store). Mirrors the iOS `LastSessionStore` protocol, made `suspend` for DataStore.
 *
 * Lifecycle (driven by `SessionActivityBridge`, A29):
 *  - **set** on `.adopted` — [setLastSessionId] with the server-issued id;
 *  - **clear** on `.exited` — [setLastSessionId] with `null` (a dead session must
 *    not be offered as "continue last", else cold-start silently spawns a NEW one);
 *  - **get** for cold-start — [lastSessionId] feeds the "继续上次会话" banner
 *    (`ColdStartPolicy`).
 */
public interface LastSessionStore {
    /**
     * The last adopted sessionId for [hostId], or null (unknown host, cleared, or —
     * for a persisted store — a value that no longer parses; untrusted at rest).
     */
    public suspend fun lastSessionId(hostId: String): String?

    /**
     * Persist [sessionId] as the last adopted session for [hostId], or clear it when
     * [sessionId] is null. Distinct hosts are keyed independently (no cross-host
     * clobbering).
     */
    public suspend fun setLastSessionId(sessionId: String?, hostId: String)
}
