package com.module.backstage.repo


import android.text.format.DateFormat
import android.util.Log
import com.module.database.room.SZDatabase
import com.module.database.room.entity.LocalOrderBean
import com.module.pay.service.HomeApiService
import com.quyunshuo.androidbaseframemvvm.base.BaseApplication
import com.quyunshuo.androidbaseframemvvm.base.mvvm.m.BaseRepository
import com.quyunshuo.androidbaseframemvvm.common.constant.Heartbeat
import javax.inject.Inject


/**
 * HomeFragment的数据仓库层
 *
 * @author Qu Yunshuo
 * @since 2021/8/5 10:59 下午
 */
class OrderDataFragmentRepo @Inject constructor() : BaseRepository() {

    private val localOrderDao = SZDatabase.getDatabase(BaseApplication.context).getLocalOrderDao()

    @Inject
    lateinit var mApi: HomeApiService


    /**
     * 查詢訂單明細，，，如何查詢國内或國外？
     * payType : 支付方式
     */
    suspend fun queryTime(startTime: String, endTime: String, payType: Int,pageNumber:Int) = request<String> {
        val params = HashMap<String, Any>()
        params["clientId"] =  Heartbeat.deviceId!!
        params["begin"] =  startTime
        params["end"] =  endTime
        params["pageNumber"] = pageNumber
        params["payType"] = payType
        params["productName"] = ""
        params["sn"] = ""
        mApi.newFindCoinOrder(params).run {
            emit(this)
        }
    }

    suspend fun queryTime(startTime:String,endTime:String): List<LocalOrderBean>{
        Log.d("backinfo","查询的时间：startTime${startTime},endTime:${endTime}")
        val all =localOrderDao.queryTime(startTime , endTime )
        return all
    }
}