package com.adealink.weparty.commonui.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.commonui.widget.nestedscrolling.NestedScrollViewModel
import com.adealink.weparty.commonui.widget.tablayout.TabLayoutMediatorViewModel

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

    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        return with(modelClass) {
            when {
                isAssignableFrom(NestedScrollViewModel::class.java) ->
                    NestedScrollViewModel()
                isAssignableFrom(TabLayoutMediatorViewModel::class.java) ->
                    TabLayoutMediatorViewModel()
                else ->
                    throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}")
            } as T
        }
    }

}