package com.miya.fastcashier.dao

import androidx.room.*
import com.miya.fastcashier.beans.ViewPayOrderData
import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum


@Dao
interface PayDataDao {

    companion object{
        const val NUM_OF_SINGLE_PAGE = 10
    }

    @Query("SELECT COUNT(*) FROM pay_data")
    fun getSize(): Int

    @Query("SELECT * FROM pay_data")
    fun getAll(): MutableList<ViewPayOrderData>

    @Query("SELECT * FROM pay_data LIMIT $NUM_OF_SINGLE_PAGE")
    fun getOnePage(): MutableList<ViewPayOrderData>

    @Query("SELECT ceil(COUNT(*))/10")
    fun getPageNum(): Int

    @Query("SELECT * FROM pay_data WHERE chanelTag =:payType ORDER BY id DESC LIMIT $NUM_OF_SINGLE_PAGE offset :beginIndex ")
    fun queryWithType(
        payType: String,
        beginIndex: Int
    ): MutableList<ViewPayOrderData>

    @Query("SELECT COUNT(*) FROM pay_data WHERE chanelTag =:payType")
    fun sizeOfType(payType: String): Int

    @Insert
    fun insertAll(list: MutableList<ViewPayOrderData>)

    @Insert
    fun insertOne(data: ViewPayOrderData)

    @Update
    fun updateOne(data: ViewPayOrderData)

    @Delete
    fun delete(user: ViewPayOrderData)
}