package com.adealink.weparty.wallet.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.wallet.detail.bean.BeanDetailViewModel
import com.adealink.weparty.wallet.detail.coin.CoinDetailViewModel
import com.adealink.weparty.wallet.detail.diamond.DiamondDetailViewModel

@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(CoinDetailViewModel::class.java) ->
                    CoinDetailViewModel()

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

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

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

}