package com.adealink.weparty.wallet.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.wallet.recharge.viewmodel.RechargeViewModel

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

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

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

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

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

}