package com.zyzf.coffeepreorder.ui.profile

import androidx.lifecycle.ViewModel
import com.zyzf.coffeepreorder.CoffeeApplication
import com.zyzf.coffeepreorder.database.AppDatabase
import com.zyzf.coffeepreorder.database.model.User
import com.zyzf.coffeepreorder.database.repository.UserRepository

class ProfileViewModel(
    private val userRepository: UserRepository
) : ViewModel() {
    suspend fun changeUser(currentUserPassw: String,
                           userOldPsswd: String,
                           userNewPsswd: String,
                           userNewPsswdConf: String,
                           userUid: Int,
                           userLogin: String,
                           userFIO: String,
                           userPhone: String,
                           userRole: String): User {
        if (userOldPsswd == currentUserPassw && userNewPsswd == userNewPsswdConf) {
            val userUid: Int? = userRepository.update(User(
                userUid, userLogin, userFIO, userPhone, userNewPsswd, userRole))
        } else {
            val userUid: Int? = userRepository.update(User(
                userUid, userLogin, userFIO, userPhone, currentUserPassw, userRole))
        }
        return userRepository.getByUid(userUid!!)!!
    }
}
