package com.adealink.weparty.order.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.adealink.weparty.order.center.viewmodel.OrderCenterViewModel

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

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

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

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

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

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

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

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

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

}