package id.ac.ubharajaya.sistemakademik

import android.content.Context
import android.content.SharedPreferences

class SessionManager(context: Context) {
    private val prefs: SharedPreferences =
        context.getSharedPreferences("user_session", Context.MODE_PRIVATE)

    companion object {
        private const val KEY_IS_LOGGED_IN = "is_logged_in"
        private const val KEY_NPM = "npm"
        private const val KEY_NAME = "name"
    }

    fun saveLogin(npm: String, name: String) {
        prefs.edit().apply {
            putBoolean(KEY_IS_LOGGED_IN, true)
            putString(KEY_NPM, npm)
            putString(KEY_NAME, name)
            apply()
        }
    }

    fun isLoggedIn(): Boolean = prefs.getBoolean(KEY_IS_LOGGED_IN, false)

    fun logout() {
        prefs.edit().clear().apply()
    }

    fun getUserNpm(): String? = prefs.getString(KEY_NPM, null)
    fun getUserName(): String? = prefs.getString(KEY_NAME, null)
}
