package ta1.cis.helper

import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit

class SharedPref (mContext : Context){
    val login = "login"
    val _username = "USERNAME"
    val token = "token"
    val mypref = "MAIN_PRF"
    val sp: SharedPreferences = mContext.getSharedPreferences(mypref, 0)
    val dimId = "dimId"
    val tgl = "tgl"
    val tempat_key="tempat"
    val statusUpdate = "statusUpdate";
    val userId = "userId"

    fun setUsername(username: String){
        sp.edit().putString(this._username, username).apply();
    }
    fun getUsername(): String = sp.getString(_username, "").toString()

    fun setStatusLogin(status : Boolean){
        sp.edit().putBoolean(login, status).apply()
    }

    fun setToken(bearer : String?){
        sp.edit().putString(token,bearer).apply();
    }
    fun getTokenBearer():String{
        return sp.getString(token,"").toString();
    }
    fun getStatusLogin() : Boolean{
        return sp.getBoolean(login, false)
    }
    fun clearAll(){
        sp.edit().clear().commit()
    }
    fun setStatusUpdate(id:Int){
        sp.edit().putInt(statusUpdate,id).apply()
    }
//
    fun getStatusUpdate():Int{
        return sp.getInt(statusUpdate,10)
    }
    fun setDimId(id:Int ? = 0){
        sp.edit().putInt(dimId,id!!).apply()
    }

    fun getDimId():Int{
        return sp.getInt(dimId,0)
    }
    fun setUserId(id:Int?){
        sp.edit().putInt(userId,id!!).apply()
    }

    fun getUserId():Int{
        return sp.getInt(userId,0)
    }
    fun setTanggal(tanggal: String?){
        sp.edit().putString(tgl,tanggal).apply()
    }
    fun getTanggal() : String{
        return sp.getString(tgl,"").toString()
    }
    fun setTempat(tempat: String?) {
        sp.edit().putString(tempat_key,tempat).apply()
    }
    fun getTempat() : String{
        return sp.getString(tempat_key,"").toString()
    }
}