package com.miya.fastcashier.dao

import androidx.room.*


@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 * FROM pay_data WHERE chanelTag =:payType ORDER BY id DESC ")
    fun queryAllWithType(payType: String): MutableList<ViewPayOrderData>

    @Query("SELECT * FROM pay_data WHERE chanelTag =:payType AND userName=:userName ORDER BY id DESC ")
    fun queryAllWithTypeAndName(payType: String,userName:String): 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)
}