package com.module.backstage.repo


import android.text.format.DateFormat
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.addressenum.PayEnum
import com.quyunshuo.androidbaseframemvvm.base.mvvm.m.BaseRepository
import javax.inject.Inject


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

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

    @Inject
    lateinit var mApi: HomeApiService


    suspend fun getAllLocalOrderData(): List<LocalOrderBean> {

        val all = localOrderDao.getAll()
        return all
    }

    suspend fun addLocalOrder(sn: String, price: Double, payType: String, name: String) {
        val sysTime = System.currentTimeMillis() //获取系统时间
        val sysTimeStr = DateFormat.format("yyyy-MM-dd HH:mm:ss", sysTime) //时间显示格式
        localOrderDao.insert(
            LocalOrderBean(
                price = price,
                payType = payType,
                sn = sn,
                time = sysTimeStr.toString(),
                name = name
            )
        )
    }

    suspend fun queryTime(startTime: String, endTime: String): List<LocalOrderBean> {
        // addLocalOrder("")
        val all = localOrderDao.queryTime(startTime, endTime)
        return all
    }
}