package com.example.smart119.datas

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

object SaveLogin {
    private const val PREF_119_NAME = "SMART119_LOGIN"
    private const val KEY_IS_LOGGED_IN = "isLoggedIn"
    private const val KEY_STR_USER_ID = "strUserId"
    private const val KEY_STR_CAR_NO = "strCarNo"

    private lateinit var preferences: SharedPreferences

    fun init(context: Context) {
        preferences = context.getSharedPreferences(PREF_119_NAME, Context.MODE_PRIVATE)
    }

    fun setLogin(isLoggedIn:Boolean) {
        preferences.edit().putBoolean(KEY_IS_LOGGED_IN, isLoggedIn).apply()
    }
    fun setUserId(strUserId:String) {
        preferences.edit().putString(KEY_STR_USER_ID, strUserId).apply()
    }
    fun setCarNo(strCarNo:String) {
        preferences.edit().putString(KEY_STR_CAR_NO, strCarNo).apply()
    }

    fun getUserId(): String? {
        return preferences.getString(KEY_STR_USER_ID, null)
    }
    fun getCarNo(): String? {
        return preferences.getString(KEY_STR_CAR_NO, null)
    }

    fun isLoggedIn(): Boolean {
        return preferences.getBoolean(KEY_IS_LOGGED_IN, false)
    }
}