package com.tt.honeyDue.data

import kotlin.test.Test
import kotlin.test.assertNotNull

/**
 * P0 — LocalDataManager ambient.
 *
 * We deliberately avoid `runComposeUiTest { }` here (same reasoning as
 * [com.tt.honeyDue.ui.screens.theme.ThemeSelectionScreenTest] — Compose UI
 * testing in commonTest is flaky on iosSimulator for this project).
 *
 * Instead this asserts the two invariants the parity-gallery plan relies on:
 *   1. [LocalDataManager] itself is a non-null reference exposed from the
 *      `com.tt.honeyDue.data` package (so screens can import it).
 *   2. The default value the ambient resolves to in production is the real
 *      [DataManager] singleton — verified indirectly by the fact that
 *      [DataManager] satisfies [IDataManager] (see [IDataManagerTest]).
 *
 * The override behavior via `CompositionLocalProvider(LocalDataManager provides fake)`
 * is exercised by the parity-gallery screens in a later phase. We don't
 * duplicate the Compose-runtime machinery here.
 */
class LocalDataManagerTest {

    @Test
    fun ambientIsExposedForScreens() {
        // Sanity: the val exists and is resolvable at the package path screens import from.
        assertNotNull(LocalDataManager, "LocalDataManager must be a top-level val in com.tt.honeyDue.data")
    }

    @Test
    fun defaultResolvesToRealDataManagerSingleton() {
        // If someone swaps the default factory to a fake by accident, this test
        // won't catch the runtime value (we can't invoke the factory without a
        // Composer), but we CAN guarantee the type contract holds — DataManager
        // must implement IDataManager so the default factory `{ DataManager }`
        // in LocalDataManager.kt type-checks.
        val manager: IDataManager = DataManager
        assertNotNull(manager)
    }
}
