package com.example.wabi.domain.repository

import android.content.Context
import android.content.SharedPreferences
import android.util.Log

object PrefManager {
    private lateinit var localDataSp: SharedPreferences

    fun initPrefManager(context: Context) {
        localDataSp = context.getSharedPreferences("root", Context.MODE_PRIVATE)
    }

    var onboard: Boolean
        get() = localDataSp.getBoolean("onboard", true)
        set(value) = localDataSp.edit().putBoolean("onboard", value).apply()

    var userTheme: Int
        get() = localDataSp.getInt("userTheme", 0)
        set(value) = localDataSp.edit().putInt("userTheme", value).apply()

    fun saveDataCurrentUser(email: String, password: String) {
        localDataSp.edit().putString("email", email).apply()
        localDataSp.edit().putString("password", password).apply()

        Log.d("pref manager", "user data was saved")
    }

    fun getDataCurrentUser(): List<String?> {
        Log.d("pref manager", "user data was got")

        return listOf(
            localDataSp.getString("email", null),
            localDataSp.getString("password", null)
        )
    }

    fun clearDataCurrentUser() {
        localDataSp.edit().remove("email").apply()
        localDataSp.edit().remove("password").apply()

        Log.d("pref manager", "user data was clean")
    }
}