package com.example.wabi.view

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.wabi.domain.repository.PrefManager
import com.example.wabi.domain.repository.UserShareDate
import com.example.wabi.domain.supabase.SupabaseServiceImpl
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject


@HiltViewModel
class MainActivityViewModel @Inject constructor(private val supabase: SupabaseServiceImpl) :
    ViewModel() {

    fun checkUserLogging() {
        val email = PrefManager.getDataCurrentUser()[0]
        val password = PrefManager.getDataCurrentUser()[1]

        viewModelScope.launch {
            if (email != null && password != null && email.isNotEmpty() && password.isNotEmpty()) {
                val response = supabase.signIn(email, password)
                if (response.error == "") {
                    UserShareDate.userIsLogging.value = true
                }
            }
        }
    }
}