package com.narutohuo.xindazhou.auth.ui.viewmodel

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

/**
 * RegisterViewModel工厂类
 */
class RegisterViewModelFactory(
    private val application: Application
) : ViewModelProvider.Factory {
    
    @Suppress("UNCHECKED_CAST")
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(RegisterViewModel::class.java)) {
            // ✅ AuthRemoteDataSource 已经很好地封装了 Network 模块
            val authRepository = AuthRepository(
                remoteDataSource = AuthRemoteDataSourceImpl(),  // ← 使用 Network 模块（已在 AuthRemoteDataSource 中展示）
                localDataSource = AuthLocalDataSourceImpl()
            )
            return RegisterViewModel(application, authRepository) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}

