package com.adealink.weparty.room.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.room.applymic.viewmodel.ApplyMicViewModel
import com.adealink.weparty.room.chat.viewmodel.ChatMessageViewModel
import com.adealink.weparty.room.chat.viewmodel.InputStateViewModel
import com.adealink.weparty.room.gift.viewmodel.RoomGiftViewModel
import com.adealink.weparty.room.member.viewmodel.RoomMemberViewModel
import com.adealink.weparty.room.micseat.viewmodel.RoomSeatViewModel

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

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

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

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

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

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

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

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

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

}