package com.adealink.weparty.playmate.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.playmate.comment.viewmodel.CommentViewModel
import com.adealink.weparty.playmate.detail.viewmodel.PlaymateDetailViewModel
import com.adealink.weparty.playmate.list.viewmodel.GuestPlaymateListViewModel
import com.adealink.weparty.playmate.list.viewmodel.PlaymateListViewModel
import com.adealink.weparty.playmate.saywelcome.viewmodel.WelcomeViewModel
import com.adealink.weparty.playmate.setting.viewmodel.OrderSettingViewModel
import com.adealink.weparty.playmate.setting.viewmodel.SkillSettingViewModel
import com.adealink.weparty.playmate.userpush.viewmodel.UserPushViewModel

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

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

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

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

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

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

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

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

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

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

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

}