package com.adealink.weparty.joinus.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.joinus.step1.viewmodel.Step1ViewModel
import com.adealink.weparty.joinus.step2.viewmodel.Step2ViewModel
import com.adealink.weparty.joinus.step3.viewmodel.Step3ViewModel

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

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

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

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

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

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

}