package com.ys.bdtp.adm.mvvm.vm.login

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ys.bdtp.adm.mvvm.model.FailureResponse
import com.ys.bdtp.adm.mvvm.model.SuccessResponse
import com.ys.bdtp.adm.mvvm.model.vo.request.Login
import kotlinx.coroutines.launch

class LoginViewModel(private val repo: LoginRepository) : ViewModel() {
    fun login(login: Login, success: (String) -> Unit, failure: (String) -> Unit) {
        viewModelScope.launch {
            when (val response = repo.login(login)) {
                is SuccessResponse -> {
                    success(response.data)
                }
                is FailureResponse -> {
                    failure(response.message)
                }
            }
        }
    }
}
