package com.adealink.weparty.log.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.frame.log.viewmodel.LogViewModel
import com.adealink.weparty.App

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

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

}