package com.example.pmulabs.viewModels

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.pmulabs.room.models.User
import com.example.pmulabs.room.repository.UserRepository
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch

class RegisterScreenViewModel(private val userRepository: UserRepository) : ViewModel() {

    private val _users = MutableLiveData<List<User>>()
    val users: LiveData<List<User>> get() = _users

    fun setUserList() {
        viewModelScope.launch {
            _users.value = userRepository.getAllUsers().first()
        }
    }

    suspend fun insertUser(user: User) {
        userRepository.insertUser(user)
    }
}