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 EntryUserViewModel(private val userRepository: UserRepository) : LoadingViewModel() {

    var userList by mutableStateOf<List<User>>(emptyList())
    fun setUserList() {
        viewModelScope.launch {
            userList=userRepository.getAllUsers()
        }
    }

    fun loginUser(username: String, password: String): User? {
        return userList.find { it.login == username && it.password == password }
    }
}