package com.hanwha.morakmorak.di

import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import com.hanwha.morakmorak.data.local.preferences.UserPreferences
import org.koin.android.ext.koin.androidApplication
import org.koin.dsl.module.module

/**
 * Created by aaron on 2019-10-02
 */

val preferencesModule = module {
    single(name = "userPrefs") { provideUserPreferences(androidApplication()) }

    single { UserPreferences(get("userPrefs")) }
}

private const val USER_PREFS_FILE_KEY = "com.hanwha.morakmorak.user_preferences"

private fun provideUserPreferences(app: Application): SharedPreferences =
        app.getSharedPreferences(USER_PREFS_FILE_KEY, Context.MODE_PRIVATE)