package com.adealink.weparty.account.viewModel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.account.login.phone.viewmodel.PhoneLoginViewModel
import com.adealink.weparty.account.login.viewmodel.LoginViewModel
import com.adealink.weparty.account.register.viewmodel.RegisterProfileViewModel

@Suppress("UNCHECKED_CAST")
class AccountViewModelFactory : ViewModelProvider.NewInstanceFactory() {

    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        return with(modelClass) {
            when {
                isAssignableFrom(LoginViewModel::class.java) ->
                    LoginViewModel()

                isAssignableFrom(RegisterProfileViewModel::class.java) ->
                    RegisterProfileViewModel()

                isAssignableFrom(PhoneLoginViewModel::class.java) ->
                    PhoneLoginViewModel()

                else ->
                    throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}")
            } as T
        }
    }

}