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

import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.narutohuo.xindazhou.common.auth.datasource.local.AuthLocalDataSourceImpl
import com.narutohuo.xindazhou.common.auth.datasource.remote.AuthRemoteDataSourceImpl
import com.narutohuo.xindazhou.common.auth.repository.AuthRepository

/**
 * LoginViewModel工厂类
 */
class LoginViewModelFactory(
    private val application: Application
) : ViewModelProvider.Factory {
    
    @Suppress("UNCHECKED_CAST")
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(LoginViewModel::class.java)) {
            val authRepository = AuthRepository(
                AuthRemoteDataSourceImpl(),
                AuthLocalDataSourceImpl()
            )
            return LoginViewModel(application, authRepository) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}
