package com.narutohuo.xindazhou.user.ui.viewmodel

import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.narutohuo.xindazhou.socketio.factory.SocketIORepositoryFactory
import com.narutohuo.xindazhou.socketio.repository.SocketIORepository

/**
 * UserViewModel工厂类
 */
class UserViewModelFactory(
    private val application: Application
) : ViewModelProvider.Factory {
    
    @Suppress("UNCHECKED_CAST")
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(UserViewModel::class.java)) {
            val socketIORepository = SocketIORepositoryFactory.getInstance()
            return UserViewModel(application, socketIORepository) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}
