package com.adealink.weparty.module.order

import androidx.lifecycle.ViewModelStoreOwner
import com.adealink.frame.aab.BaseDynamicModule
import com.adealink.frame.aab.constant.AABModuleNotInitError
import com.adealink.frame.base.Rlt
import com.adealink.weparty.R
import com.adealink.weparty.module.order.data.OrderDetailInfo
import com.adealink.weparty.module.order.data.OrderDiscountInfo
import com.adealink.weparty.module.order.viewmodel.IOrderViewModel

object OrderModule : BaseDynamicModule<IOrderService>(IOrderService::class),
    IOrderService {

    override val featureName: String
        get() = "order"

    override val moduleNameResId: Int
        get() = R.string.module_order

    override fun emptyService(): IOrderService {
        return object : IOrderService {

            override fun getService(): IOrderService? {
                return null
            }

            override fun onLogout() {
            }

            override fun getOrderViewModel(owner: ViewModelStoreOwner): IOrderViewModel? {
                return null
            }

            override suspend fun queryUnCompleteOrder(uid: String): Rlt<List<OrderDetailInfo>> {
                return Rlt.Failed(AABModuleNotInitError())
            }

            override fun queryDiscountInfo() {
            }

            override suspend fun suspendQueryDiscountInfo(): Rlt<Any> {
                return Rlt.Failed(AABModuleNotInitError())
            }

            override fun getDiscountInfo(): OrderDiscountInfo? {
                return null
            }
        }
    }

    override fun onLogout() {
        getService().onLogout()
    }

    override fun getOrderViewModel(owner: ViewModelStoreOwner): IOrderViewModel? {
        return getService().getOrderViewModel(owner)
    }

    override suspend fun queryUnCompleteOrder(uid: String): Rlt<List<OrderDetailInfo>> {
        return getService().queryUnCompleteOrder(uid)
    }

    override fun queryDiscountInfo() {
        getService().queryDiscountInfo()
    }

    override suspend fun suspendQueryDiscountInfo(): Rlt<Any> {
        return getService().suspendQueryDiscountInfo()
    }

    override fun getDiscountInfo(): OrderDiscountInfo? {
        return getService().getDiscountInfo()
    }
}