package com.adealink.weparty.share.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.share.qrcode.viewmodel.QRCodeViewModel

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

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

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

}