package com.adealink.weparty.profile.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.profile.dynamic.viewmodel.DynamicListViewModel
import com.adealink.weparty.profile.dynamic.viewmodel.DynamicViewModel
import com.adealink.weparty.profile.dynamic.viewmodel.PublishDynamicViewModel
import com.adealink.weparty.profile.edit.viewmodel.EditProfileViewModel
import com.adealink.weparty.profile.relation.viewmodel.BlackViewModel
import com.adealink.weparty.profile.relation.viewmodel.FollowViewModel
import com.adealink.weparty.profile.relation.viewmodel.VisitorViewModel
import com.adealink.weparty.profile.ui.about.viewmodel.ProfilePageViewModel

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

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

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

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

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

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

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

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

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

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

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

}