package com.adealink.weparty.im.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.im.list.viewmodel.SessionListViewModel
import com.adealink.weparty.im.session.viewmodel.SessionSettingViewModel
import com.adealink.weparty.im.session.viewmodel.SessionViewModel

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

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

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

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

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

}