package com.example.myapplication.database.entities.composeui

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.myapplication.database.entities.model.User
import com.example.myapplication.database.entities.repository.UserRepository
import kotlinx.coroutines.launch

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

    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 }
    }
}