package com.applemand.zmanim.core.common

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import javax.inject.Inject
import javax.inject.Qualifier
import javax.inject.Singleton

@Qualifier annotation class IoDispatcher
@Qualifier annotation class DefaultDispatcher
@Qualifier annotation class MainDispatcher

/**
 * Wrapper so all :core modules depend on an abstraction, not on Dispatchers.IO directly.
 * Instantiated by Hilt via AppDispatchersModule in :app.
 */
@Singleton
class AppDispatchers @Inject constructor(
    @IoDispatcher val io: CoroutineDispatcher,
    @DefaultDispatcher val default: CoroutineDispatcher,
    @MainDispatcher val main: CoroutineDispatcher,
) {
    companion object {
        fun real() = AppDispatchers(
            io = Dispatchers.IO,
            default = Dispatchers.Default,
            main = Dispatchers.Main.immediate,
        )
    }
}
