package com.example.wabi.view.screeens.profile

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavHostController
import com.example.wabi.domain.navigation.NavigationProvider
import com.example.wabi.domain.navigation.Routes
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 ProfileViewModel @Inject constructor(
    private val supabase: SupabaseServiceImpl, private val nav: NavigationProvider
) : ViewModel() {
    fun signOutCurrentUser(navController: NavHostController) {
        viewModelScope.launch {
            supabase.signOut()
            PrefManager.initPrefManager(UserShareDate.context!!)
            PrefManager.clearDataCurrentUser()
            UserShareDate.userIsLogging.value = false
            nav.goToNextScreen(navHostController = navController, Routes.PROFILE, Routes.PROFILE)
        }
    }
}