package com.example.myapplication.database.room.viewmodel.user

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.viewModelScope
import com.example.myapplication.database.room.model.user.User
import com.example.myapplication.database.room.repository.online.UserRepository
import com.example.myapplication.database.room.viewmodel.LoadingViewModel
import kotlinx.coroutines.launch

class CurrentUserViewModel(private val userRepository: UserRepository) : LoadingViewModel(){
    val argument = mutableStateOf<String?>(null)
    private val userid = mutableStateOf<Int?>(null)
    var user by mutableStateOf<User?>(null)

    fun setArgument(arg: String) {
        argument.value = arg
        userid.value = arg.toInt()
        viewModelScope.launch {
            user = userRepository.getUserById(userid.value)
        }
    }

    fun setNullUser() {
        user = null
    }
}